[
  {
    "path": ".gitignore",
    "content": "*~\n.idea/\n.idea_modules/\n.manager/\nworkspace.xml\nbin/\ndocs/\ntarget/\nlib_managed/\nsrc_managed/\nproject/boot/\nproject/plugins/project/\n"
  },
  {
    "path": "LICENSE",
    "content": "                  GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\f\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\f\n                  GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n\n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\f\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\f\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\f\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\f\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\f\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\f\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n                            NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\f\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n\n"
  },
  {
    "path": "README",
    "content": "Scalala is a high performance numeric linear algebra library for Scala,\nwith rich Matlab-like operators on vectors and matrices; a library of\nnumerical routines; support for plotting.\n\nThis software is released under the LGPL.  See LICENSE for details. \n\n(c) 2008- | Daniel Ramage | dramage | http://cs.stanford.edu/~dramage \n\nWith contributions from:\n  David Hall <dlwh>\n  Jason Zaugg <retronym>\n  Alexander Lehmann <afwlehmann>\n  Jonathan Merritt <lancelet>\n  aerskine\n  And others (email me if you've contributed code and aren't listed)\n\nBuilding upon and/or borrowing from solid libraries:\n  JFreeChart  http://www.jfree.org/jfreechart/\n  Netlib      http://code.google.com/p/netlib-java/\n  MTJ         http://code.google.com/p/matrix-toolkits-java/ \n  iText       http://www.itextpdf.com/\n\nThe source currently lives on github.  You can download a copy:\n\n  git clone https://github.com/scalala/Scalala.git\n\nScalala is built with sbt, which is included in the repository or\ncan be downloaded from https://github.com/harrah/xsbt/wiki.\n\nRun sbt (./sbt) and invoke one or more of the following targets:\n  update      -- Downloads scalala's dependencies\n  compile     -- Builds the library\n  test        -- Runs the unit tests\n  doc         -- Builds scaladoc for the public API\n  proguard    -- Builds a distributable jar\n  gen-idea    -- Generate an IntelliJ IDEA project\n\nFor project maintainers, the project can be deployed with:\n  publish\n\nTo run an interactive console, either do so through sbt (console or\nconsole-quick) or run sbt's proguard target, and then:\n  java -jar target/scala_2.8.1/scalala*.min.jar\n\nDocumentation is available here:\n  https://github.com/scalala/Scalala/wiki/Scalala\n\nAnd informal support is available here:\n  http://groups.google.com/group/scalala\n\n"
  },
  {
    "path": "build.sbt",
    "content": "\nname := \"scalala\"\n\nversion := \"1.0.0.RC3-SNAPSHOT\"\n\norganization := \"org.scalala\"\n\nscalaVersion := \"2.9.2\"\n\ncrossScalaVersions := Seq(\"2.8.2\", \"2.9.1\", \"2.9.2\")\n\nresolvers ++= Seq(\n  \"ScalaNLP Maven2\" at \"http://repo.scalanlp.org/repo\",\n  \"Scala Tools Snapshots\" at \"http://scala-tools.org/repo-snapshots/\"\n)\n\nlibraryDependencies ++= Seq(\n  \"com.googlecode.netlib-java\" % \"netlib-java\" % \"0.9.3\",\n  \"jfree\" % \"jcommon\" % \"1.0.16\",\n  \"jfree\" % \"jfreechart\" % \"1.0.13\",\n  \"org.apache.xmlgraphics\" % \"xmlgraphics-commons\" % \"1.3.1\", // for eps gen\n  // \"org.apache.xmlgraphics\" % \"batik-dom\" % \"1.7\",    // for svg gen\n  // \"org.apache.xmlgraphics\" % \"batik-svggen\" % \"1.7\", // for svg gen\n  \"com.lowagie\" % \"itext\" % \"2.1.5\" intransitive(),  // for pdf gen\n  \"junit\" % \"junit\" % \"4.5\" % \"test\"\n)\n\nlibraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>\n  deps :+ (\"org.scala-lang\" % \"scala-compiler\" % sv)\n}\n\nlibraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>\n  val Scala210 = \"\"\"2\\.10\\.0.*\"\"\".r\n  sv match {\n    case \"2.9.1\" | \"2.9.2\" | Scala210() =>\n      deps :+ (\"jline\" % \"jline\" % \"0.9.94\") // (\"org.scala-lang\" % \"jline\" % \"2.9.1\")\n    case x if x.startsWith(\"2.8\") =>\n      deps :+ (\"jline\" % \"jline\" % \"0.9.94\")\n    case x       => error(\"Unsupported Scala version \" + x)\n  }\n}\n\nlibraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>\n  val Scala210 = \"\"\"2\\.10\\.0.*\"\"\".r\n  sv match {\n    case Scala210() => deps\n    case \"2.9.1\" | \"2.9.2\" =>\n      (deps :+ (\"org.scalatest\" % \"scalatest\" % \"1.4.RC2\" % \"test\")\n            :+ (\"org.scala-tools.testing\" % \"scalacheck_2.9.1\" % \"1.9\" % \"test\"))\n    case x if x.startsWith(\"2.8\") =>\n      (deps :+ (\"org.scalatest\" % \"scalatest\" % \"1.3\" % \"test\")\n            :+ (\"org.scala-tools.testing\" % \"scalacheck_2.8.1\" % \"1.8\" % \"test\"))\n    case x  => error(\"Unsupported Scala version \" + x)\n  }\n}\n\npublishTo <<= (version) { version: String =>\n  val nexus = \"http://nexus.scala-tools.org/content/repositories/\"\n  if (version.trim.endsWith(\"SNAPSHOT\")) Some(\"snapshots\" at nexus + \"snapshots/\")\n  else                                   Some(\"releases\"  at nexus + \"releases/\")\n}\n\ncredentials += Credentials(Path.userHome / \".ivy2\" / \".credentials\")\n\njavacOptions ++= Seq(\"-source\", \"1.5\", \"-target\", \"1.5\")\n\nscalacOptions ++= Seq(\"-no-specialization\",\"-deprecation\",\"-target:jvm-1.5\")\n\ninitialCommands := scala.io.Source.fromFile(\"src/main/resources/scalala.scala\").getLines.mkString(\"\\n\")\n\nmainClass in (Compile,packageBin) := Some(\"scalala.ScalalaConsole\")\n\njavaOptions += \"-Xmx2g\"\n\nseq(ProguardPlugin.proguardSettings :_*)\n\nproguardOptions ++= Seq (\n  \"-keep class scalala.** { *; }\",\n  \"-keep class org.jfree.** { *; }\",\n  keepMain(\"scalala.ScalalaConsole$\"),\n  keepMain(\"scala.tools.nsc.MainGenericRunner\"),\n  \"-dontoptimize\",\n  \"-dontobfuscate\",\n  keepLimitedSerializability,\n  keepAllScala,\n  \"-keep class ch.epfl.** { *; }\",\n  \"-keep interface scala.ScalaObject\"\n)\n\n// seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)\n\n"
  },
  {
    "path": "project/build.properties",
    "content": "sbt.version=0.11.3"
  },
  {
    "path": "project/plugins.sbt",
    "content": "\nresolvers += \"Proguard plugin repo\" at \"http://siasia.github.com/maven2\"\n\nlibraryDependencies <+= sbtVersion(v => \"com.github.siasia\" %% \"xsbt-proguard-plugin\" % (\"0.11.2-0.1.1\"))\n\naddSbtPlugin(\"com.github.mpeltonen\" % \"sbt-idea\" % \"1.0.0\")\n"
  },
  {
    "path": "sbt",
    "content": "#!/usr/bin/env bash\n#\n# A more capable sbt runner, coincidentally also called sbt.\n# Author: Paul Phillips <paulp@typesafe.com>\n\n# todo - make this dynamic\ndeclare -r sbt_release_version=0.11.3\ndeclare -r sbt_snapshot_version=0.13.0-SNAPSHOT\n\nunset sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir\nunset scala_version java_home sbt_explicit_version\nunset verbose debug quiet\n\nbuild_props_sbt () {\n  if [[ -f project/build.properties ]]; then\n    versionLine=$(grep ^sbt.version project/build.properties)\n    versionString=${versionLine##sbt.version=}\n    echo \"$versionString\"\n  fi\n}\n\nupdate_build_props_sbt () {\n  local ver=\"$1\"\n  local old=$(build_props_sbt)\n\n  if [[ $ver == $old ]]; then\n    return\n  elif [[ -f project/build.properties ]]; then\n    perl -pi -e \"s/^sbt\\.version=.*\\$/sbt.version=${ver}/\" project/build.properties\n    grep -q '^sbt.version=' project/build.properties || echo \"sbt.version=${ver}\" >> project/build.properties\n\n    echo !!!\n    echo !!! Updated file project/build.properties setting sbt.version to: $ver\n    echo !!! Previous value was: $old\n    echo !!!\n  fi\n}\n\nsbt_version () {\n  if [[ -n $sbt_explicit_version ]]; then\n    echo $sbt_explicit_version\n  else\n    local v=$(build_props_sbt)\n    if [[ -n $v ]]; then\n      echo $v\n    else\n      echo $sbt_release_version\n    fi\n  fi\n}\n\nechoerr () {\n  echo 1>&2 \"$@\"\n}\nvlog () {\n  [[ $verbose || $debug ]] && echoerr \"$@\"\n}\ndlog () {\n  [[ $debug ]] && echoerr \"$@\"\n}\n\n# this seems to cover the bases on OSX, and someone will\n# have to tell me about the others.\nget_script_path () {\n  local path=\"$1\"\n  [[ -L \"$path\" ]] || { echo \"$path\" ; return; }\n\n  local target=$(readlink \"$path\")\n  if [[ \"${target:0:1}\" == \"/\" ]]; then\n    echo \"$target\"\n  else\n    echo \"$(dirname $path)/$target\"\n  fi\n}\n\n# a ham-fisted attempt to move some memory settings in concert\n# so they need not be dicked around with individually.\nget_mem_opts () {\n  local mem=${1:-1536}\n  local perm=$(( $mem / 4 ))\n  (( $perm > 256 )) || perm=256\n  (( $perm < 1024 )) || perm=1024\n  local codecache=$(( $perm / 2 ))\n  \n  echo \"-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m\"\n}\n\ndie() {\n  echo \"Aborting: $@\"\n  exit 1\n}\n\nmake_url () {\n  groupid=\"$1\"\n  category=\"$2\"\n  version=\"$3\"\n  \n  echo \"http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar\"\n}\n\ndeclare -r default_jvm_opts=\"-Dfile.encoding=UTF8\"\ndeclare -r default_sbt_opts=\"-XX:+CMSClassUnloadingEnabled\"\ndeclare -r default_sbt_mem=1536\ndeclare -r noshare_opts=\"-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy\"\ndeclare -r sbt_opts_file=\".sbtopts\"\ndeclare -r jvm_opts_file=\".jvmopts\"\ndeclare -r latest_28=\"2.8.2\"\ndeclare -r latest_29=\"2.9.1\"\ndeclare -r latest_210=\"2.10.0-SNAPSHOT\"\n\ndeclare -r script_path=$(get_script_path \"$BASH_SOURCE\")\ndeclare -r script_dir=\"$(dirname $script_path)\"\ndeclare -r script_name=\"$(basename $script_path)\"\n\n# some non-read-onlies set with defaults\ndeclare java_cmd=java\ndeclare sbt_launch_dir=\"$script_dir/.lib\"\ndeclare sbt_mem=$default_sbt_mem\n\n# pull -J and -D options to give to java.\ndeclare -a residual_args\ndeclare -a java_args\ndeclare -a scalac_args\ndeclare -a sbt_commands\n\nbuild_props_scala () {\n  if [[ -f project/build.properties ]]; then\n    versionLine=$(grep ^build.scala.versions project/build.properties)\n    versionString=${versionLine##build.scala.versions=}\n    echo ${versionString%% .*}\n  fi\n}\n\nexecRunner () {\n  # print the arguments one to a line, quoting any containing spaces\n  [[ $verbose || $debug ]] && echo \"# Executing command line:\" && {\n    for arg; do\n      if printf \"%s\\n\" \"$arg\" | grep -q ' '; then\n        printf \"\\\"%s\\\"\\n\" \"$arg\"\n      else\n        printf \"%s\\n\" \"$arg\"\n      fi\n    done\n    echo \"\"\n  }\n\n  exec \"$@\"\n}\n\nsbt_groupid () {\n  case $(sbt_version) in\n        0.7.*) echo org.scala-tools.sbt ;;\n       0.10.*) echo org.scala-tools.sbt ;;\n    0.11.[12]) echo org.scala-tools.sbt ;;\n            *) echo org.scala-sbt ;;\n  esac\n}\n\nsbt_artifactory_list () {\n  local version0=$(sbt_version)\n  local version=${version0%-SNAPSHOT}\n  local url=\"http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/\"\n  dlog \"Looking for snapshot list at: $url \"\n  \n  curl -s --list-only \"$url\" | \\\n    grep -F $version | \\\n    perl -e 'print reverse <>' | \\\n    perl -pe 's#^<a href=\"([^\"/]+).*#$1#;'\n}\n\nmake_release_url () {\n  make_url $(sbt_groupid) releases $(sbt_version)\n}\n\n# argument is e.g. 0.13.0-SNAPSHOT\n# finds the actual version (with the build id) at artifactory\nmake_snapshot_url () {\n  for ver in $(sbt_artifactory_list); do\n    local url=$(make_url $(sbt_groupid) snapshots $ver)\n    dlog \"Testing $url\"\n    curl -s --head \"$url\" >/dev/null\n    dlog \"curl returned: $?\"\n    echo \"$url\"\n    return\n  done\n}\n\njar_url () {\n  case $(sbt_version) in\n             0.7.*) echo \"http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar\" ;;\n        *-SNAPSHOT) make_snapshot_url ;;\n                 *) make_release_url ;;\n  esac\n}\n\njar_file () {\n  echo \"$sbt_launch_dir/$1/sbt-launch.jar\"\n}\n\ndownload_url () {\n  local url=\"$1\"\n  local jar=\"$2\"\n  \n  echo \"Downloading sbt launcher $(sbt_version):\"\n  echo \"  From  $url\"\n  echo \"    To  $jar\"\n\n  mkdir -p $(dirname \"$jar\") && {\n    if which curl >/dev/null; then\n      curl --fail --silent \"$url\" --output \"$jar\"\n    elif which wget >/dev/null; then\n      wget --quiet -O \"$jar\" \"$url\"\n    fi\n  } && [[ -f \"$jar\" ]]\n}\n\nacquire_sbt_jar () {\n  sbt_url=\"$(jar_url)\"\n  sbt_jar=\"$(jar_file $(sbt_version))\"\n\n  [[ -f \"$sbt_jar\" ]] || download_url \"$sbt_url\" \"$sbt_jar\"\n}\n\nusage () {\n  cat <<EOM\nUsage: $script_name [options]\n\n  -h | -help         print this message\n  -v | -verbose      this runner is chattier\n  -d | -debug        set sbt log level to Debug\n  -q | -quiet        set sbt log level to Error\n  -no-colors         disable ANSI color codes\n  -sbt-create        start sbt even if current directory contains no sbt project\n  -sbt-dir   <path>  path to global settings/plugins directory (default: ~/.sbt/<version>)\n  -sbt-boot  <path>  path to shared boot directory (default: ~/.sbt/boot in 0.11 series)\n  -ivy       <path>  path to local Ivy repository (default: ~/.ivy2)\n  -mem    <integer>  set memory options (default: $sbt_mem, which is\n                       $(get_mem_opts $sbt_mem) )\n  -no-share          use all local caches; no sharing\n  -offline           put sbt in offline mode\n  -jvm-debug <port>  Turn on JVM debugging, open at the given port.\n  -batch             Disable interactive mode\n\n  # sbt version (default: from project/build.properties if present, else latest release)\n  !!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which\n  !!! contains an sbt.version property is to update the file on disk.  That's what this does.\n  -sbt-version  <version>   use the specified version of sbt \n  -sbt-jar      <path>      use the specified jar as the sbt launcher\n  -sbt-snapshot             use a snapshot version of sbt\n  -sbt-launch-dir <path>    directory to hold sbt launchers (default: $sbt_launch_dir)\n\n  # scala version (default: as chosen by sbt)\n  -28                       use $latest_28\n  -29                       use $latest_29\n  -210                      use $latest_210\n  -scala-home <path>        use the scala build at the specified directory\n  -scala-version <version>  use the specified version of scala\n\n  # java version (default: java from PATH, currently $(java -version |& grep version))\n  -java-home <path>         alternate JAVA_HOME\n\n  # jvm options and output control\n  JAVA_OPTS     environment variable holding jvm args, if unset uses \"$default_jvm_opts\"\n  SBT_OPTS      environment variable holding jvm args, if unset uses \"$default_sbt_opts\"\n  .jvmopts      if file is in sbt root, it is prepended to the args given to the jvm\n  .sbtopts      if file is in sbt root, it is prepended to the args given to **sbt**\n  -Dkey=val     pass -Dkey=val directly to the jvm\n  -J-X          pass option -X directly to the jvm (-J is stripped)\n  -S-X          add -X to sbt's scalacOptions (-J is stripped)\n\nIn the case of duplicated or conflicting options, the order above\nshows precedence: JAVA_OPTS lowest, command line options highest.\nEOM\n}\n\naddJava () {\n  dlog \"[addJava] arg = '$1'\"\n  java_args=( \"${java_args[@]}\" \"$1\" )\n}\naddSbt () {\n  dlog \"[addSbt] arg = '$1'\"\n  sbt_commands=( \"${sbt_commands[@]}\" \"$1\" )\n}\naddScalac () {\n  dlog \"[addScalac] arg = '$1'\"\n  scalac_args=( \"${scalac_args[@]}\" \"$1\" )\n}\naddResidual () {\n  dlog \"[residual] arg = '$1'\"\n  residual_args=( \"${residual_args[@]}\" \"$1\" )\n}\naddResolver () {\n  addSbt \"set resolvers in ThisBuild += $1\"\n}\naddDebugger () {\n  addJava \"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1\"\n}\nget_jvm_opts () {\n  # echo \"${JAVA_OPTS:-$default_jvm_opts}\"\n  # echo \"${SBT_OPTS:-$default_sbt_opts}\"\n\n  [[ -f \"$jvm_opts_file\" ]] && cat \"$jvm_opts_file\"\n}\n\nprocess_args ()\n{\n  require_arg () {\n    local type=\"$1\"\n    local opt=\"$2\"\n    local arg=\"$3\"\n    \n    if [[ -z \"$arg\" ]] || [[ \"${arg:0:1}\" == \"-\" ]]; then\n      die \"$opt requires <$type> argument\"\n    fi\n  }\n  while [[ $# -gt 0 ]]; do\n    case \"$1\" in\n       -h|-help) usage; exit 1 ;;\n    -v|-verbose) verbose=1 && shift ;;\n      -d|-debug) debug=1 && shift ;;\n      -q|-quiet) quiet=1 && shift ;;\n\n           -ivy) require_arg path \"$1\" \"$2\" && addJava \"-Dsbt.ivy.home=$2\" && shift 2 ;;\n           -mem) require_arg integer \"$1\" \"$2\" && sbt_mem=\"$2\" && shift 2 ;;\n     -no-colors) addJava \"-Dsbt.log.noformat=true\" && shift ;;\n      -no-share) addJava \"$noshare_opts\" && shift ;;\n      -sbt-boot) require_arg path \"$1\" \"$2\" && addJava \"-Dsbt.boot.directory=$2\" && shift 2 ;;\n       -sbt-dir) require_arg path \"$1\" \"$2\" && sbt_dir=\"$2\" && shift 2 ;;\n     -debug-inc) addJava \"-Dxsbt.inc.debug=true\" && shift ;;\n       -offline) addSbt \"set offline := true\" && shift ;;\n     -jvm-debug) require_arg port \"$1\" \"$2\" && addDebugger $2 && shift 2 ;;\n         -batch) exec </dev/null && shift ;;\n\n    -sbt-create) sbt_create=true && shift ;;\n  -sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;\n       -sbt-jar) require_arg path \"$1\" \"$2\" && sbt_jar=\"$2\" && shift 2 ;;\n   -sbt-version) require_arg version \"$1\" \"$2\" && sbt_explicit_version=\"$2\" && shift 2 ;;\n-sbt-launch-dir) require_arg path \"$1\" \"$2\" && sbt_launch_dir=\"$2\" && shift 2 ;;\n -scala-version) require_arg version \"$1\" \"$2\" && addSbt \"set scalaVersion := \\\"$2\\\"\" && shift 2 ;;\n    -scala-home) require_arg path \"$1\" \"$2\" && addSbt \"set scalaHome in ThisBuild := Some(file(\\\"$2\\\"))\" && shift 2 ;;\n     -java-home) require_arg path \"$1\" \"$2\" && java_cmd=\"$2/bin/java\" && shift 2 ;;\n\n            -D*) addJava \"$1\" && shift ;;\n            -J*) addJava \"${1:2}\" && shift ;;\n            -S*) addScalac \"${1:2}\" && shift ;;\n            -28) addSbt \"++ $latest_28\" && shift ;;\n            -29) addSbt \"++ $latest_29\" && shift ;;\n           -210) addSbt \"++ $latest_210\" && shift ;;\n\n              *) addResidual \"$1\" && shift ;;\n    esac\n  done\n  \n  [[ $debug ]] && {\n    case $(sbt_version) in\n     0.7.*) addSbt \"debug\" ;; \n         *) addSbt \"set logLevel in Global := Level.Debug\" ;;\n    esac\n  }\n  [[ $quiet ]] && {\n    case $(sbt_version) in\n     0.7.*) ;; \n         *) addSbt \"set logLevel in Global := Level.Error\" ;;\n    esac\n  }\n}\n\n# if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner\n[[ -f \"$sbt_opts_file\" ]] && {\n  sbtargs=()\n  while IFS= read -r arg; do\n    sbtargs=( \"${sbtargs[@]}\" \"$arg\" )\n  done <\"$sbt_opts_file\"\n\n  set -- \"${sbtargs[@]}\" \"$@\"\n}\n\n# process the combined args, then reset \"$@\" to the residuals\nprocess_args \"$@\"\nset -- \"${residual_args[@]}\"\nargumentCount=$#\n\n# set scalacOptions if we were given any -S opts\n[[ ${#scalac_args[@]} -eq 0 ]] || addSbt \"set scalacOptions in ThisBuild += \\\"${scalac_args[@]}\\\"\"\n\n# Update build.properties no disk to set explicit version - sbt gives us no choice\n[[ -n \"$sbt_explicit_version\" ]] && update_build_props_sbt \"$sbt_explicit_version\"\necho \"Detected sbt version $(sbt_version)\"\n\n[[ -n \"$scala_version\" ]] && echo \"Overriding scala version to $scala_version\"\n\n# no args - alert them there's stuff in here\n(( $argumentCount > 0 )) || echo \"Starting $script_name: invoke with -help for other options\"\n\n# verify this is an sbt dir or -create was given\n[[ -f ./build.sbt || -d ./project || -n \"$sbt_create\" ]] || {\n  cat <<EOM\n$(pwd) doesn't appear to be an sbt project.\nIf you want to start sbt anyway, run:\n  $0 -sbt-create\n\nEOM\n  exit 1\n}\n\n# pick up completion if present; todo\n[[ -f .sbt_completion.sh ]] && source .sbt_completion.sh\n\n# no jar? download it.\n[[ -f \"$sbt_jar\" ]] || acquire_sbt_jar || {\n  # still no jar? uh-oh.\n  echo \"Download failed. Obtain the jar manually and place it at $sbt_jar\"\n  exit 1\n}\n\n[[ -n \"$sbt_dir\" ]] || {\n  sbt_dir=~/.sbt/$(sbt_version)\n  addJava \"-Dsbt.global.base=$sbt_dir\"\n  echo \"Using $sbt_dir as sbt dir, -sbt-dir to override.\"\n}\n\n# since sbt 0.7 doesn't understand iflast\n(( ${#residual_args[@]} == 0 )) && residual_args=( \"shell\" )\n\n# run sbt\nexecRunner \"$java_cmd\" \\\n  $(get_mem_opts $sbt_mem) \\\n  $(get_jvm_opts) \\\n  ${java_args[@]} \\\n  -jar \"$sbt_jar\" \\\n  \"${sbt_commands[@]}\" \\\n  \"${residual_args[@]}\""
  },
  {
    "path": "src/main/java/scalala/library/random/MersenneTwisterFast.java",
    "content": "package scalala.library.random;\nimport java.io.*;\nimport java.util.*;\n\n/**\n * <h3>MersenneTwister and MersenneTwisterFast</h3>\n * <p><b>Version 13</b>, based on version MT199937(99/10/29)\n * of the Mersenne Twister algorithm found at\n * <a href=\"http://www.math.keio.ac.jp/matumoto/emt.html\">\n * The Mersenne Twister Home Page</a>, with the initialization\n * improved using the new 2002/1/26 initialization algorithm\n * By Sean Luke, October 2004.\n *\n * <p><b>MersenneTwister</b> is a drop-in subclass replacement\n * for java.util.Random.  It is properly synchronized and\n * can be used in a multithreaded environment.  On modern VMs such\n * as HotSpot, it is approximately 1/3 slower than java.util.Random.\n *\n * <p><b>MersenneTwisterFast</b> is not a subclass of java.util.Random.  It has\n * the same public methods as Random does, however, and it is\n * algorithmically identical to MersenneTwister.  MersenneTwisterFast\n * has hard-code inlined all of its methods directly, and made all of them\n * final (well, the ones of consequence anyway).  Further, these\n * methods are <i>not</i> synchronized, so the same MersenneTwisterFast\n * instance cannot be shared by multiple threads.  But all this helps\n * MersenneTwisterFast achieve well over twice the speed of MersenneTwister.\n * java.util.Random is about 1/3 slower than MersenneTwisterFast.\n *\n * <h3>About the Mersenne Twister</h3>\n * <p>This is a Java version of the C-program for MT19937: Integer version.\n * The MT19937 algorithm was created by Makoto Matsumoto and Takuji Nishimura,\n * who ask: \"When you use this, send an email to: matumoto@math.keio.ac.jp\n * with an appropriate reference to your work\".  Indicate that this\n * is a translation of their algorithm into Java.\n *\n * <p><b>Reference. </b>\n * Makato Matsumoto and Takuji Nishimura,\n * \"Mersenne Twister: A 623-Dimensionally Equidistributed Uniform\n * Pseudo-Random Number Generator\",\n * <i>ACM Transactions on Modeling and. Computer Simulation,</i>\n * Vol. 8, No. 1, January 1998, pp 3--30.\n *\n * <h3>About this Version</h3>\n *\n * <p><b>Changes Since V12:</b> clone() method added.\n *\n * <p><b>Changes Since V11:</b> stateEquals(...) method added.  MersenneTwisterFast\n * is equal to other MersenneTwisterFasts with identical state; likewise\n * MersenneTwister is equal to other MersenneTwister with identical state.\n * This isn't equals(...) because that requires a contract of immutability\n * to compare by value.\n *\n * <p><b>Changes Since V10:</b> A documentation error suggested that\n * setSeed(int[]) required an int[] array 624 long.  In fact, the array\n * can be any non-zero length.  The new version also checks for this fact.\n *\n * <p><b>Changes Since V9:</b> readState(stream) and writeState(stream)\n * provided.\n *\n * <p><b>Changes Since V8:</b> setSeed(int) was only using the first 28 bits\n * of the seed; it should have been 32 bits.  For small-number seeds the\n * behavior is identical.\n *\n * <p><b>Changes Since V7:</b> A documentation error in MersenneTwisterFast\n * (but not MersenneTwister) stated that nextDouble selects uniformly from\n * the full-open interval [0,1].  It does not.  nextDouble's contract is\n * identical across MersenneTwisterFast, MersenneTwister, and java.util.Random,\n * namely, selection in the half-open interval [0,1).  That is, 1.0 should\n * not be returned.  A similar contract exists in nextFloat.\n *\n * <p><b>Changes Since V6:</b> License has changed from LGPL to BSD.\n * New timing information to compare against\n * java.util.Random.  Recent versions of HotSpot have helped Random increase\n * in speed to the point where it is faster than MersenneTwister but slower\n * than MersenneTwisterFast (which should be the case, as it's a less complex\n * algorithm but is synchronized).\n *\n * <p><b>Changes Since V5:</b> New empty constructor made to work the same\n * as java.util.Random -- namely, it seeds based on the current time in\n * milliseconds.\n *\n * <p><b>Changes Since V4:</b> New initialization algorithms.  See\n * (see <a href=\"http://www.math.keio.ac.jp/matumoto/MT2002/emt19937ar.html\"</a>\n * http://www.math.keio.ac.jp/matumoto/MT2002/emt19937ar.html</a>)\n *\n * <p>The MersenneTwister code is based on standard MT19937 C/C++\n * code by Takuji Nishimura,\n * with suggestions from Topher Cooper and Marc Rieffel, July 1997.\n * The code was originally translated into Java by Michael Lecuyer,\n * January 1999, and the original code is Copyright (c) 1999 by Michael Lecuyer.\n *\n * <h3>Java notes</h3>\n *\n * <p>This implementation implements the bug fixes made\n * in Java 1.2's version of Random, which means it can be used with\n * earlier versions of Java.  See\n * <a href=\"http://www.javasoft.com/products/jdk/1.2/docs/api/java/util/Random.html\">\n * the JDK 1.2 java.util.Random documentation</a> for further documentation\n * on the random-number generation contracts made.  Additionally, there's\n * an undocumented bug in the JDK java.util.Random.nextBytes() method,\n * which this code fixes.\n *\n * <p> Just like java.util.Random, this\n * generator accepts a long seed but doesn't use all of it.  java.util.Random\n * uses 48 bits.  The Mersenne Twister instead uses 32 bits (int size).\n * So it's best if your seed does not exceed the int range.\n *\n * <p>MersenneTwister can be used reliably\n * on JDK version 1.1.5 or above.  Earlier Java versions have serious bugs in\n * java.util.Random; only MersenneTwisterFast (and not MersenneTwister nor\n * java.util.Random) should be used with them.\n *\n * <h3>License</h3>\n *\n * Copyright (c) 2003 by Sean Luke. <br>\n * Portions copyright (c) 1993 by Michael Lecuyer. <br>\n * All rights reserved. <br>\n *\n * <p>Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n * <ul>\n * <li> Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n * <li> Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n * <li> Neither the name of the copyright owners, their employers, nor the\n * names of its contributors may be used to endorse or promote products\n * derived from this software without specific prior written permission.\n * </ul>\n * <p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNERS OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n *\n @version 13\n*/\n\n// Note: this class is hard-inlined in all of its methods.  This makes some of\n// the methods well-nigh unreadable in their complexity.  In fact, the Mersenne\n// Twister is fairly easy code to understand: if you're trying to get a handle\n// on the code, I strongly suggest looking at MersenneTwister.java first.\n// -- Sean\n\npublic class MersenneTwisterFast implements Serializable, Cloneable\n    {\n    // Period parameters\n    private static final int N = 624;\n    private static final int M = 397;\n    private static final int MATRIX_A = 0x9908b0df;   //    private static final * constant vector a\n    private static final int UPPER_MASK = 0x80000000; // most significant w-r bits\n    private static final int LOWER_MASK = 0x7fffffff; // least significant r bits\n\n\n    // Tempering parameters\n    private static final int TEMPERING_MASK_B = 0x9d2c5680;\n    private static final int TEMPERING_MASK_C = 0xefc60000;\n\n    private int mt[]; // the array for the state vector\n    private int mti; // mti==N+1 means mt[N] is not initialized\n    private int mag01[];\n\n    // a good initial seed (of int size, though stored in a long)\n    //private static final long GOOD_SEED = 4357;\n\n    private double __nextNextGaussian;\n    private boolean __haveNextNextGaussian;\n\n    /* We're overriding all internal data, to my knowledge, so this should be okay */\n    public Object clone() throws CloneNotSupportedException\n        {\n        MersenneTwisterFast f = (MersenneTwisterFast)(super.clone());\n        f.mt = (int[])(mt.clone());\n        f.mag01 = (int[])(mag01.clone());\n        return f;\n        }\n\n    public boolean stateEquals(Object o)\n        {\n        if (o==this) return true;\n        if (o == null || !(o instanceof MersenneTwisterFast))\n            return false;\n        MersenneTwisterFast other = (MersenneTwisterFast) o;\n        if (mti != other.mti) return false;\n        for(int x=0;x<mag01.length;x++)\n            if (mag01[x] != other.mag01[x]) return false;\n        for(int x=0;x<mt.length;x++)\n            if (mt[x] != other.mt[x]) return false;\n        return true;\n        }\n\n    /** Reads the entire state of the MersenneTwister RNG from the stream */\n    public void readState(DataInputStream stream) throws IOException\n        {\n        int len = mt.length;\n        for(int x=0;x<len;x++) mt[x] = stream.readInt();\n\n        len = mag01.length;\n        for(int x=0;x<len;x++) mag01[x] = stream.readInt();\n\n        mti = stream.readInt();\n        __nextNextGaussian = stream.readDouble();\n        __haveNextNextGaussian = stream.readBoolean();\n        }\n\n    /** Writes the entire state of the MersenneTwister RNG to the stream */\n    public void writeState(DataOutputStream stream) throws IOException\n        {\n        int len = mt.length;\n        for(int x=0;x<len;x++) stream.writeInt(mt[x]);\n\n        len = mag01.length;\n        for(int x=0;x<len;x++) stream.writeInt(mag01[x]);\n\n        stream.writeInt(mti);\n        stream.writeDouble(__nextNextGaussian);\n        stream.writeBoolean(__haveNextNextGaussian);\n        }\n\n    /**\n     * Constructor using the default seed.\n     */\n    public MersenneTwisterFast()\n        {\n        this(System.currentTimeMillis());\n        }\n\n    /**\n     * Constructor using a given seed.  Though you pass this seed in\n     * as a long, it's best to make sure it's actually an integer.\n     *\n     */\n    public MersenneTwisterFast(final long seed)\n        {\n        setSeed(seed);\n        }\n\n\n    /**\n     * Constructor using an array of integers as seed.\n     * Your array must have a non-zero length.  Only the first 624 integers\n     * in the array are used; if the array is shorter than this then\n     * integers are repeatedly used in a wrap-around fashion.\n     */\n    public MersenneTwisterFast(final int[] array)\n        {\n        setSeed(array);\n        }\n\n\n    /**\n     * Initalize the pseudo random number generator.  Don't\n     * pass in a long that's bigger than an int (Mersenne Twister\n     * only uses the first 32 bits for its seed).\n     */\n\n    synchronized public void setSeed(final long seed)\n        {\n        // Due to a bug in java.util.Random clear up to 1.2, we're\n        // doing our own Gaussian variable.\n        __haveNextNextGaussian = false;\n\n        mt = new int[N];\n\n        mag01 = new int[2];\n        mag01[0] = 0x0;\n        mag01[1] = MATRIX_A;\n\n        mt[0]= (int)(seed & 0xffffffff);\n        for (mti=1; mti<N; mti++)\n            {\n            mt[mti] =\n                (1812433253 * (mt[mti-1] ^ (mt[mti-1] >>> 30)) + mti);\n            /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */\n            /* In the previous versions, MSBs of the seed affect   */\n            /* only MSBs of the array mt[].                        */\n            /* 2002/01/09 modified by Makoto Matsumoto             */\n            mt[mti] &= 0xffffffff;\n            /* for >32 bit machines */\n            }\n        }\n\n\n    /**\n     * Sets the seed of the MersenneTwister using an array of integers.\n     * Your array must have a non-zero length.  Only the first 624 integers\n     * in the array are used; if the array is shorter than this then\n     * integers are repeatedly used in a wrap-around fashion.\n     */\n\n    synchronized public void setSeed(final int[] array)\n        {\n        if (array.length == 0)\n            throw new IllegalArgumentException(\"Array length must be greater than zero\");\n        int i, j, k;\n        setSeed(19650218);\n        i=1; j=0;\n        k = (N>array.length ? N : array.length);\n        for (; k!=0; k--)\n            {\n            mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >>> 30)) * 1664525)) + array[j] + j; /* non linear */\n            mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */\n            i++;\n            j++;\n            if (i>=N) { mt[0] = mt[N-1]; i=1; }\n            if (j>=array.length) j=0;\n            }\n        for (k=N-1; k!=0; k--)\n            {\n            mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >>> 30)) * 1566083941)) - i; /* non linear */\n            mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */\n            i++;\n            if (i>=N)\n                {\n                mt[0] = mt[N-1]; i=1;\n                }\n            }\n        mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */\n        }\n\n\n    public final int nextInt()\n        {\n        int y;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return y;\n        }\n\n\n\n    public final short nextShort()\n        {\n        int y;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return (short)(y >>> 16);\n        }\n\n\n\n    public final char nextChar()\n        {\n        int y;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return (char)(y >>> 16);\n        }\n\n\n    public final boolean nextBoolean()\n        {\n        int y;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return (boolean)((y >>> 31) != 0);\n        }\n\n\n\n    /** This generates a coin flip with a probability <tt>probability</tt>\n        of returning true, else returning false.  <tt>probability</tt> must\n        be between 0.0 and 1.0, inclusive.   Not as precise a random real\n        event as nextBoolean(double), but twice as fast. To explicitly\n        use this, remember you may need to cast to float first. */\n\n    public final boolean nextBoolean(final float probability)\n        {\n        int y;\n\n        if (probability < 0.0f || probability > 1.0f)\n            throw new IllegalArgumentException (\"probability must be between 0.0 and 1.0 inclusive.\");\n        if (probability==0.0f) return false;            // fix half-open issues\n        else if (probability==1.0f) return true;        // fix half-open issues\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return (y >>> 8) / ((float)(1 << 24)) < probability;\n        }\n\n\n    /** This generates a coin flip with a probability <tt>probability</tt>\n        of returning true, else returning false.  <tt>probability</tt> must\n        be between 0.0 and 1.0, inclusive. */\n\n    public final boolean nextBoolean(final double probability)\n        {\n        int y;\n        int z;\n\n        if (probability < 0.0 || probability > 1.0)\n            throw new IllegalArgumentException (\"probability must be between 0.0 and 1.0 inclusive.\");\n        if (probability==0.0) return false;             // fix half-open issues\n        else if (probability==1.0) return true; // fix half-open issues\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];\n                }\n            z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];\n\n            mti = 0;\n            }\n\n        z = mt[mti++];\n        z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)\n        z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)\n        z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)\n        z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)\n\n        /* derived from nextDouble documentation in jdk 1.2 docs, see top */\n        return ((((long)(y >>> 6)) << 27) + (z >>> 5)) / (double)(1L << 53) < probability;\n        }\n\n\n    public final byte nextByte()\n        {\n        int y;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return (byte)(y >>> 24);\n        }\n\n\n    public final void nextBytes(byte[] bytes)\n        {\n        int y;\n\n        for (int x=0;x<bytes.length;x++)\n            {\n            if (mti >= N)   // generate N words at one time\n                {\n                int kk;\n                final int[] mt = this.mt; // locals are slightly faster\n                final int[] mag01 = this.mag01; // locals are slightly faster\n\n                for (kk = 0; kk < N - M; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                for (; kk < N-1; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n                mti = 0;\n                }\n\n            y = mt[mti++];\n            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n            bytes[x] = (byte)(y >>> 24);\n            }\n        }\n\n\n    public final long nextLong()\n        {\n        int y;\n        int z;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];\n                }\n            z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];\n\n            mti = 0;\n            }\n\n        z = mt[mti++];\n        z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)\n        z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)\n        z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)\n        z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)\n\n        return (((long)y) << 32) + (long)z;\n        }\n\n\n\n    /** Returns a long drawn uniformly from 0 to n-1.  Suffice it to say,\n        n must be > 0, or an IllegalArgumentException is raised. */\n    public final long nextLong(final long n)\n        {\n        if (n<=0)\n            throw new IllegalArgumentException(\"n must be > 0\");\n\n        long bits, val;\n        do\n            {\n            int y;\n            int z;\n\n            if (mti >= N)   // generate N words at one time\n                {\n                int kk;\n                final int[] mt = this.mt; // locals are slightly faster\n                final int[] mag01 = this.mag01; // locals are slightly faster\n\n                for (kk = 0; kk < N - M; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                for (; kk < N-1; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n                mti = 0;\n                }\n\n            y = mt[mti++];\n            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n            if (mti >= N)   // generate N words at one time\n                {\n                int kk;\n                final int[] mt = this.mt; // locals are slightly faster\n                final int[] mag01 = this.mag01; // locals are slightly faster\n\n                for (kk = 0; kk < N - M; kk++)\n                    {\n                    z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];\n                    }\n                for (; kk < N-1; kk++)\n                    {\n                    z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];\n                    }\n                z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];\n\n                mti = 0;\n                }\n\n            z = mt[mti++];\n            z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)\n            z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)\n            z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)\n            z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)\n\n            bits = (((((long)y) << 32) + (long)z) >>> 1);\n            val = bits % n;\n            } while (bits - val + (n-1) < 0);\n        return val;\n        }\n\n    /** Returns a random double in the half-open range from [0.0,1.0).  Thus 0.0 is a valid\n        result but 1.0 is not. */\n    public final double nextDouble()\n        {\n        int y;\n        int z;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];\n                }\n            z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];\n\n            mti = 0;\n            }\n\n        z = mt[mti++];\n        z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)\n        z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)\n        z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)\n        z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)\n\n        /* derived from nextDouble documentation in jdk 1.2 docs, see top */\n        return ((((long)(y >>> 6)) << 27) + (z >>> 5)) / (double)(1L << 53);\n        }\n\n\n\n\n\n    public final double nextGaussian()\n        {\n        if (__haveNextNextGaussian)\n            {\n            __haveNextNextGaussian = false;\n            return __nextNextGaussian;\n            }\n        else\n            {\n            double v1, v2, s;\n            do\n                {\n                int y;\n                int z;\n                int a;\n                int b;\n\n                if (mti >= N)   // generate N words at one time\n                    {\n                    int kk;\n                    final int[] mt = this.mt; // locals are slightly faster\n                    final int[] mag01 = this.mag01; // locals are slightly faster\n\n                    for (kk = 0; kk < N - M; kk++)\n                        {\n                        y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                        }\n                    for (; kk < N-1; kk++)\n                        {\n                        y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                        }\n                    y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                    mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n                    mti = 0;\n                    }\n\n                y = mt[mti++];\n                y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n                y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n                y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n                y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n                if (mti >= N)   // generate N words at one time\n                    {\n                    int kk;\n                    final int[] mt = this.mt; // locals are slightly faster\n                    final int[] mag01 = this.mag01; // locals are slightly faster\n\n                    for (kk = 0; kk < N - M; kk++)\n                        {\n                        z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];\n                        }\n                    for (; kk < N-1; kk++)\n                        {\n                        z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];\n                        }\n                    z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                    mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];\n\n                    mti = 0;\n                    }\n\n                z = mt[mti++];\n                z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)\n                z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)\n                z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)\n                z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)\n\n                if (mti >= N)   // generate N words at one time\n                    {\n                    int kk;\n                    final int[] mt = this.mt; // locals are slightly faster\n                    final int[] mag01 = this.mag01; // locals are slightly faster\n\n                    for (kk = 0; kk < N - M; kk++)\n                        {\n                        a = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+M] ^ (a >>> 1) ^ mag01[a & 0x1];\n                        }\n                    for (; kk < N-1; kk++)\n                        {\n                        a = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+(M-N)] ^ (a >>> 1) ^ mag01[a & 0x1];\n                        }\n                    a = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                    mt[N-1] = mt[M-1] ^ (a >>> 1) ^ mag01[a & 0x1];\n\n                    mti = 0;\n                    }\n\n                a = mt[mti++];\n                a ^= a >>> 11;                          // TEMPERING_SHIFT_U(a)\n                a ^= (a << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(a)\n                a ^= (a << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(a)\n                a ^= (a >>> 18);                        // TEMPERING_SHIFT_L(a)\n\n                if (mti >= N)   // generate N words at one time\n                    {\n                    int kk;\n                    final int[] mt = this.mt; // locals are slightly faster\n                    final int[] mag01 = this.mag01; // locals are slightly faster\n\n                    for (kk = 0; kk < N - M; kk++)\n                        {\n                        b = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+M] ^ (b >>> 1) ^ mag01[b & 0x1];\n                        }\n                    for (; kk < N-1; kk++)\n                        {\n                        b = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                        mt[kk] = mt[kk+(M-N)] ^ (b >>> 1) ^ mag01[b & 0x1];\n                        }\n                    b = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                    mt[N-1] = mt[M-1] ^ (b >>> 1) ^ mag01[b & 0x1];\n\n                    mti = 0;\n                    }\n\n                b = mt[mti++];\n                b ^= b >>> 11;                          // TEMPERING_SHIFT_U(b)\n                b ^= (b << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(b)\n                b ^= (b << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(b)\n                b ^= (b >>> 18);                        // TEMPERING_SHIFT_L(b)\n\n                /* derived from nextDouble documentation in jdk 1.2 docs, see top */\n                v1 = 2 *\n                    (((((long)(y >>> 6)) << 27) + (z >>> 5)) / (double)(1L << 53))\n                    - 1;\n                v2 = 2 * (((((long)(a >>> 6)) << 27) + (b >>> 5)) / (double)(1L << 53))\n                    - 1;\n                s = v1 * v1 + v2 * v2;\n                } while (s >= 1 || s==0);\n            double multiplier = /*Strict*/Math.sqrt(-2 * /*Strict*/Math.log(s)/s);\n            __nextNextGaussian = v2 * multiplier;\n            __haveNextNextGaussian = true;\n            return v1 * multiplier;\n            }\n        }\n\n\n\n\n\n    /** Returns a random float in the half-open range from [0.0f,1.0f).  Thus 0.0f is a valid\n        result but 1.0f is not. */\n    public final float nextFloat()\n        {\n        int y;\n\n        if (mti >= N)   // generate N words at one time\n            {\n            int kk;\n            final int[] mt = this.mt; // locals are slightly faster\n            final int[] mag01 = this.mag01; // locals are slightly faster\n\n            for (kk = 0; kk < N - M; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            for (; kk < N-1; kk++)\n                {\n                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                }\n            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n            mti = 0;\n            }\n\n        y = mt[mti++];\n        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n        return (y >>> 8) / ((float)(1 << 24));\n        }\n\n\n\n    /** Returns an integer drawn uniformly from 0 to n-1.  Suffice it to say,\n        n must be > 0, or an IllegalArgumentException is raised. */\n    public final int nextInt(final int n)\n        {\n        if (n<=0)\n            throw new IllegalArgumentException(\"n must be > 0\");\n\n        if ((n & -n) == n)  // i.e., n is a power of 2\n            {\n            int y;\n\n            if (mti >= N)   // generate N words at one time\n                {\n                int kk;\n                final int[] mt = this.mt; // locals are slightly faster\n                final int[] mag01 = this.mag01; // locals are slightly faster\n\n                for (kk = 0; kk < N - M; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                for (; kk < N-1; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n                mti = 0;\n                }\n\n            y = mt[mti++];\n            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n            return (int)((n * (long) (y >>> 1) ) >> 31);\n            }\n\n        int bits, val;\n        do\n            {\n            int y;\n\n            if (mti >= N)   // generate N words at one time\n                {\n                int kk;\n                final int[] mt = this.mt; // locals are slightly faster\n                final int[] mag01 = this.mag01; // locals are slightly faster\n\n                for (kk = 0; kk < N - M; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                for (; kk < N-1; kk++)\n                    {\n                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);\n                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];\n                    }\n                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);\n                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n                mti = 0;\n                }\n\n            y = mt[mti++];\n            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)\n            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)\n            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)\n            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)\n\n            bits = (y >>> 1);\n            val = bits % n;\n            } while(bits - val + (n-1) < 0);\n        return val;\n        }\n    }\n\n"
  },
  {
    "path": "src/main/resources/scalala.scala",
    "content": "import scalala.scalar._;\nimport scalala.tensor.::;\nimport scalala.tensor.mutable._;\nimport scalala.tensor.dense._;\nimport scalala.tensor.sparse._;\nimport scalala.library.Library._;\nimport scalala.library.LinearAlgebra._;\nimport scalala.library.Statistics._;\nimport scalala.library.Plotting._;\nimport scalala.operators.Implicits._;\n\n"
  },
  {
    "path": "src/main/scala/scalala/ScalalaConsole.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n * \n * Copyright (C) 2008- Daniel Ramage\n * \n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA \n */\npackage scalala;\n\n/**\n * Runs Scalala in a console.\n * \n * @author dlwh,dramage\n */\nobject ScalalaConsole {\n  def main(args : Array[String]) {\n    // read scalala.scala to a tmp file\n    val stream = this.getClass.getClassLoader.getResourceAsStream(\"scalala.scala\");\n    val file = java.io.File.createTempFile(\"scalala-startup-\", \".scala\");\n    file.deleteOnExit;\n    val fos = new java.io.PrintStream(new java.io.FileOutputStream(file));\n    for (line <- scala.io.Source.fromInputStream(stream).getLines()) {\n      fos.println(line);\n    }\n    fos.close();\n\n    // redirect to invoking the standard scala main method\n    val method = Class.forName(\"scala.tools.nsc.MainGenericRunner\").\n      getMethod(\"main\", classOf[Array[String]]);\n\n    // augmented arguments\n    val aurg : Object = (\n      List[String](\n        \"-nocompdaemon\",\n        \"-classpath\", System.getProperty(\"java.class.path\"),\n        \"-no-specialization\",\n        \"-Yrepl-sync\",\n        \"-usejavacp\",\n        \"-i\", file.getAbsolutePath\n      ) ++ args\n    ).toArray[String];\n\n    method.invoke(null, aurg);\n  }\n  \n  /** The width of the console, or 80 if it can't be discovered. */\n  lazy val terminalWidth : Int = {\n    // this ugly try-catch is here to use scala's built-in jline,\n    // which only exists in scala > 2.9\n    try {\n      type Terminal = { def getWidth() : Int; def getHeight() : Int; }\n      val terminal = Class.forName(\"scala.tools.jline.TerminalFactory\").\n        getMethod(\"create\").invoke(null).asInstanceOf[Terminal];\n      terminal.getWidth()\n    } catch {\n      case _ => try {\n        type Terminal = { def getTerminalWidth() : Int; def getTerminalHeight() : Int; }\n        val terminal = Class.forName(\"jline.Terminal\").\n          getMethod(\"getInstance\").invoke(null).asInstanceOf[Terminal];\n        terminal.getTerminalWidth()\n      } catch {\n        case _ => 80\n      }\n    }\n  };\n\n  /** The height of the console, or 24 if it can't be discovered. */\n  lazy val terminalHeight : Int = {\n    // this ugly try-catch is here to use scala's built-in jline,\n    // which only exists in scala > 2.9\n    try {\n      type Terminal = { def getWidth() : Int; def getHeight() : Int; }\n      val terminal = Class.forName(\"scala.tools.jline.TerminalFactory\").\n        getMethod(\"create\").invoke(null).asInstanceOf[Terminal];\n      terminal.getHeight();\n    } catch {\n      case _ => try {\n        type Terminal = { def getTerminalWidth() : Int; def getTerminalHeight() : Int; }\n        val terminal = Class.forName(\"jline.Terminal\").\n          getMethod(\"getInstance\").invoke(null).asInstanceOf[Terminal];\n        terminal.getTerminalHeight()\n      } catch {\n        case _ => 24\n      }\n    }\n  };\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/collection/sparse/SparseArray.scala",
    "content": "/*\n Copyright 2009 David Hall, Daniel Ramage\n \n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at \n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License. \n*/\n\npackage scalala.collection.sparse;\n\nimport scala.collection.generic._;\nimport scala.collection.mutable._;\n\nimport scalala.operators._;\nimport scalala.scalar.Scalar\nimport java.util.Arrays\n;\n\n/**\n * <p>Nearly-drop-in replacement for Array[T](length) that does not store\n * default array values.  Internally, the SparseArray data structure\n * stores an array of indexes in packed, sorted order, and a\n * corresponding packed array of values.  Updates are linear in\n * the number of non-zero array elements, while accesses are\n * logarithmic.  This class is not threadsafe for simultaneous\n * reads and writes, but more than one thread can read simultaneously\n * if no threads are writing.</p>\n *\n * <p>Note that the DefaultArrayValue must be a constant reference -- no\n * clever tricks like creating new instances of type T are supported\n * by the nature of the way this map works.  Otherwise, iterating\n * over the size of the array would cause the SparseArray to become\n * (inefficiently) dense.</p>\n *\n * @param length The virtual length of the array.\n * @param index The indices of the array, in packed sorted order.\n * @param data The data of the array, in corresponding positions to index.\n * @param used The number of used elements in index and data.\n * @param initialActiveLength The initial length of the sparse data structures\n *   when creating new instances.\n *\n * @author dlwh, dramage\n */\n@SerialVersionUID(1L)\nfinal class SparseArray[@specialized T]\n(val length : Int, protected var index : Array[Int], protected var data : Array[T], protected var used : Int, initialActiveLength : Int)\n(implicit m : ClassManifest[T], df : DefaultArrayValue[T]) extends Serializable {\n\n  def copy: SparseArray[T] = {\n    val newData = m.newArray(data.length)\n    Array.copy(data,0,newData,0,data.length)\n    new SparseArray(length, Arrays.copyOf(index, index.length), newData, used, initialActiveLength)\n  }\n\n\n  def this(length : Int, initialActiveLength : Int = 3)(implicit m : ClassManifest[T], d : DefaultArrayValue[T]) =\n    this(length, new Array[Int](initialActiveLength), new Array[T](initialActiveLength), 0, initialActiveLength)(m, d);\n\n  checkInvariants()\n  \n  private def checkInvariants() { // check rep invariants\n    require(length >= 0, \"Length must be non-negative\");\n    require(used >= 0 && used <= length, \"Used must be <= length and >= 0\");\n    if (used > 0) {\n      require(index(0) >= 0, \"Indexes must be ordered and non-negative\");\n      var i = 1;\n      while (i < used) {\n        require(index(i-1) < index(i) && index(i) >= 0, \"Indexes must be ordered and non-negative\");\n        i +=1;\n      }\n    }\n  }\n\n  /** Default value. */\n  val default = df.value;\n\n  /** Iterator over used indexes and values */\n  def iterator = Iterator.range(0, used).map(i => (index(i),data(i)));\n\n  /** Used indexes. */\n  def indexIterator = index.iterator.take(used);\n\n  /** Used values. */\n  def valueIterator = data.iterator.take(used);\n\n  /** Key value pairs of non-default entries. */\n  def activeIterator = indexIterator zip valueIterator;\n\n  /** A copy of the keys in this array. */\n  def indexArray : Array[Int] = index.take(used);\n\n  /** A copy of the values in this array. */\n  def valueArray : Array[T] = data.take(used);\n\n  /** Raw access to the underlying data array. Use with caution */\n  def rawValueArray : Array[T] = data\n\n  /**\n   * Returns the offset into index and data for the requested vector\n   * index.  If the requested index is not found, the return value is\n   * negative and can be converted into an insertion point with ~rv.\n   */\n  private def findOffset(i : Int) : Int = {\n    if (i < 0 || i >= length)\n      throw new IndexOutOfBoundsException(\"Index \"+i+\" out of bounds [0,\"+used+\")\");\n\n    if (used == 0) {\n      // empty list; do nothing\n      return -1;\n    } else if (i > index(used-1)) {\n      // special case for end of list - this is a big win for growing sparse arrays\n      return ~used;\n    } else {\n      // regular binary search from begin to end (inclusive)\n      var begin = 0;\n      var end = used - 1;\n\n      // Simple optimization: position i can't be after offset i.\n      if(end > i)\n        end = i;\n\n      var mid = (end + begin) >> 1;\n      while (begin <= end) {\n        mid = (end + begin) >> 1;\n        if (index(mid) < i)\n          begin = mid + 1;\n        else if (index(mid) > i)\n          end = mid - 1;\n        else\n          return mid;\n      }\n\n      // no match found, return insertion point\n      if (i <= index(mid))\n        return ~mid;       // Insert here (before mid)\n      else\n        return ~(mid + 1); // Insert after mid\n    }\n  }\n\n  def apply(i : Int) : T = {\n    val offset = findOffset(i);\n    if (offset >= 0) data(offset) else default;\n  }\n\n  def get(i: Int) : Option[T] = {\n    val offset = findOffset(i);\n    if (offset >= 0) Some(data(offset)) else None;\n  }\n\n  def getOrElse(i : Int, value : =>T) : T = {\n    val offset = findOffset(i);\n    if (offset >= 0) data(offset) else value;\n  }\n\n  def getOrElseUpdate(i : Int, value : =>T) : T = {\n    val offset = findOffset(i);\n    if (offset >= 0) data(offset)\n    else {\n      val v = value;\n      update(i,v)\n      v;\n    }\n  }\n\n  /** Returns the size of the array. */\n  def activeLength = used;\n\n  /** Returns the index of the item stored at the given offset. */\n  def indexAt(offset : Int) : Int = {\n    if (offset >= used) throw new ArrayIndexOutOfBoundsException();\n    index(offset);\n  }\n\n  /** Returns the value of the item stored at the given offset. */\n  def valueAt(offset : Int) : T = {\n    if (offset >= used) throw new ArrayIndexOutOfBoundsException();\n    data(offset);\n  }\n\n  /**\n   * Sets the given value at the given index if the value is not\n   * equal to the current default.  The data and\n   * index arrays will be grown to support the insertion if\n   * necessary.  The growth schedule doubles the amount\n   * of allocated memory at each allocation request up until\n   * the sparse array contains 1024 values, at which point\n   * the growth is additive: an additional n * 1024 spaces will\n   * be allocated for n in 1,2,4,8,16.  The largest amount of\n   * space added to this vector will be an additional 16*1024*(sizeof(T)+4),\n   * which is 196608 bytes at a time for a SparseVector[Double],\n   * although more space is needed temporarily while moving to the\n   * new arrays.\n   */\n  def update(i : Int, value : T) = {\n    val offset = findOffset(i);\n    if (offset >= 0) {\n      // found at offset\n      data(offset) = value;\n    } else if (value != default) {\n      // need to insert at ~offset\n      val insertPos = ~offset;\n\n      used += 1;\n\n      if (used > data.length) {\n        // need to grow array\n        val newLength = {\n          if      (data.length == 0)     { 4 }\n          else if (data.length < 0x0400) { data.length * 2 }\n          else if (data.length < 0x0800) { data.length + 0x0400 }\n          else if (data.length < 0x1000) { data.length + 0x0800 }\n          else if (data.length < 0x2000) { data.length + 0x1000 }\n          else if (data.length < 0x4000) { data.length + 0x2000 }\n          else { data.length + 0x4000 };\n        };\n\n        // allocate new arrays\n        val newIndex = new Array[Int](newLength);\n        val newData  = new Array[T](newLength);\n\n        // copy existing data into new arrays\n        System.arraycopy(index, 0, newIndex, 0, insertPos);\n        System.arraycopy(data, 0, newData, 0, insertPos);\n        System.arraycopy(index, insertPos, newIndex, insertPos + 1, used - insertPos - 1);\n        System.arraycopy(data,  insertPos, newData,  insertPos + 1, used - insertPos - 1);\n        \n        // update pointers\n        index = newIndex;\n        data = newData;\n      } else if (used - insertPos > 1) {\n        // need to make room for new element mid-array\n        System.arraycopy(index, insertPos, index, insertPos + 1, used - insertPos - 1);\n        System.arraycopy(data,  insertPos, data,  insertPos + 1, used - insertPos - 1);\n      }\n\n      // assign new value\n      index(insertPos) = i;\n      data(insertPos) = value;\n    }\n  }\n\n  /** Clears this array, resetting to the initial size. */\n  def clear() {\n    use(new Array[Int](initialActiveLength), new Array[T](initialActiveLength), 0);\n  }\n\n  /** Pre-allocate space in this array for all active indexes in other. */\n  def reserve[O](other : SparseArray[O]) {\n    val rv = new SparseArray[T](this.length, this.used + other.used);\n    var i = 0;\n    var j = 0;\n    while (j < other.used) {\n      val indexI = index(i);\n      val indexJ = index(j);\n      while (i < used && indexI < indexJ) {\n        rv(indexI) = data(i);\n        i += 1;\n      }\n      rv(indexJ) = this(indexJ);\n      j += 1;\n    }\n    while (i < used) {\n      rv(index(i)) = data(i);\n      i += 1;\n    }\n    use(rv.index, rv.data, rv.used);\n  }\n\n  /** Compacts the array by removing all stored default values. */\n  def compact() {\n    val nz = { // number of non-zeros\n      var _nz = 0;\n      var i = 0;\n      while (i < used) {\n        if (data(i) != default) {\n          _nz += 1;\n        }\n        i += 1;\n      }\n      _nz;\n    }\n\n    val newData  = new Array[T](nz);\n    val newIndex = new Array[Int](nz);\n\n    var i = 0;\n    var o = 0;\n    while (i < used) {\n      if (data(i) != default) {\n        newData(o) = data(i);\n        newIndex(o) = index(i);\n        o += 1;\n      }\n      i += 1;\n    }\n\n    use(newIndex, newData, nz);\n  }\n\n  /** Use the given index and data arrays, of which the first inUsed are valid. */\n  private def use(inIndex : Array[Int], inData : Array[T], inUsed : Int) = {\n    // no need to rep-check since method is private and all callers satisfy\n    // these invariants.\n\n    data = inData;\n    index = inIndex;\n    used = inUsed;\n  }\n  \n  /** Sets this array to be a copy of the given other array. */\n  def set(that : SparseArray[T]) = {\n    if (this.length != that.length) {\n      throw new IllegalArgumentException(\"SparseArrays must be the same length\");\n    }\n    use(that.index.clone, that.data.clone, that.used);\n  }\n\n  private def checkrep() {\n    if (index == null || data == null)\n      throw new IllegalArgumentException(\"Index and data must be non-null\");\n    if (index.length != data.length)\n      throw new IllegalArgumentException(\"Index and data sizes do not match\");\n    if (index.length < used)\n      throw new IllegalArgumentException(\"Used is greater than provided array\");\n    if (index(0) < 0 || index(0) >= used)\n      throw new IllegalArgumentException(\"use inIndex out of range contains illegal offset @ 0\");\n    var i = 1;\n    while (i < used) {\n      if (index(i) < 0 || index(i) >= used || index(i) < index(i-1))\n        throw new IllegalArgumentException(\"use inIndex out of range contains illegal offset @ \"+i);\n      i += 1;\n    }\n  }\n\n  /**\n   * Maps all values.  If f(this.default) is not equal to the new default\n   * value, the result may be an efficiently dense (or almost dense) paired\n   * array.\n   */\n  def map[B:ClassManifest:DefaultArrayValue](f : T=>B) : SparseArray[B] = {\n    val newDefault = implicitly[DefaultArrayValue[B]].value;\n    if (used < length && f(default) == newDefault) {\n      // some default values but f(default) is still default\n      val newIndex = new Array[Int](used);\n      val newData = new Array[B](used);\n      var i = 0; var o = 0;\n      while (i < used) {\n        newIndex(o) = index(i);\n        val newValue = f(data(i));\n        if (newValue != newDefault) {\n          newData(o) = newValue;\n          o += 1;\n        }\n        i += 1;\n      }\n      new SparseArray[B](length, newIndex, newData, o, initialActiveLength);\n    } else {\n      // no default values stored or f(default) is non-default\n      val newDefault = f(default);\n      val newIndex = new Array[Int](length);\n      val newData = new Array[B](length);\n      var i = 0;\n      var o = 0;\n      while (i < used) {\n        while (o < index(i)) {\n          newIndex(o) = o;\n          newData(o) = newDefault;\n          o += 1;\n        }\n        newIndex(o) = o;\n        newData(o) = f(data(i));\n        o += 1;\n        i += 1;\n      }\n      while (o < length) {\n        newIndex(o) = o;\n        newData(o) = newDefault;\n        o += 1;\n      }\n      val rv = new SparseArray[B](length, newIndex, newData, length, initialActiveLength);\n      rv.compact;\n      rv;\n    }\n  }\n\n  /**\n   * Filter's the array by removing all values for which f is false.\n   */\n  def filter(f : T=>Boolean) : SparseArray[T] = {\n    val newIndex = new Array[Int](used);\n    val newData = new Array[T](used);\n    var i = 0; var o = 0;\n    while (i < used) {\n      if (f(data(i))) {\n        newIndex(o) = index(i) - (i - o);\n        newData(o) = data(i);\n        o += 1;\n      }\n      i += 1;\n    }\n\n    if (f(default)) {\n      // if default values are accepted, assume we're full length.\n      var newLength = length - (i - o);\n      \n      // ... and subtract from that length how many defined tail elements\n      // were filtered ...\n      var ii = used - 1;\n      while (ii >= 0 && index(ii) > newIndex(o) && index(ii) == newLength - 1) {\n        ii -= 1;\n        newLength -= 1;\n      }\n      new SparseArray[T](newLength, newIndex, newData, o, initialActiveLength);\n    } else {\n      // if default values are not accepted, return a \"dense\" array by\n      // setting each position in newIndex consecutively to forget missing\n      // values\n      val newLength = o;\n      new SparseArray[T](newLength, Array.range(0,newLength), newData.take(newLength), newLength, initialActiveLength);\n    }\n  }\n\n  /**\n   * Tranforms all elements this array by applying the given function. If\n   * f(default) == default, then only updates non-default values.  Otherwise,\n   * the map essentially becomes dense -- not so efficient an operation!\n   */\n  def transform(f : T=>T) = {\n    val newDefault = f(default);\n    if (newDefault == default) {\n      var i = 0;\n      while (i < used) {\n        data(i) = f(data(i));\n        i += 1;\n      }\n    } else {\n      val newIndex = Array.range(0, length);\n      val newData = new Array[T](length);\n      var i = 0;\n      var o = 0;\n      while (i < used) {\n        while (o < index(i)) {\n          newData(o) = newDefault;\n          o += 1;\n        }\n        newData(o) = f(data(i));\n        o += 1;\n        i += 1;\n      }\n      while (o < length) {\n        newData(o) = newDefault;\n        o += 1;\n      }\n      use(newIndex, newData, length);\n    }\n  }\n\n  /** Applies the given function to each non-default element. */\n  def foreachActivePair[U](f: ((Int,T) => U)) {\n    var i = 0;\n    while(i < used) {\n      f(index(i), data(i));\n      i += 1;\n    }\n  }\n\n  /** Applies the given function to each non-default element. */\n  def foreachActiveValue[U](f: T => U) {\n    var i = 0;\n    while(i < used) {\n      f(data(i));\n      i += 1;\n    }\n  }\n\n  /** Applies the given function to each non-default element. */\n  def foreachActiveKey[U](f: Int => U) {\n    var i = 0;\n    while(i < used) {\n      f(index(i));\n      i += 1;\n    }\n  }\n\n  def toArray =\n    Array.tabulate(length)(apply);\n\n  def toList =\n    List.tabulate(length)(apply);\n\n  def toIndexedSeq =\n    List.tabulate(length)(apply);\n\n  def toMap =\n    (indexIterator zip valueIterator).toMap;\n\n  override def hashCode = {\n    var rv = 0;\n    var i = 0;\n    while (i < used) {\n      if (data(i) != default) {\n        rv += 17*rv + data(i).hashCode*7 + index(i);\n      }\n      i += 1;\n    }\n    rv;\n  }\n\n  override def equals(other : Any) : Boolean = other match {\n    case that : SparseArray[_] =>\n      var thisI = 0;\n      var thatI = 0;\n      while (thisI < this.used && thatI < that.used) {\n        if (this.index(thisI) < that.index(thatI)) {\n          if (this.data(thisI) != that.default) return false;\n          thisI += 1;\n        } else if (that.index(thatI) < this.index(thisI)) {\n          if (that.data(thatI) != this.default) return false;\n          thatI += 1;\n        } else { // this.index(thisI) == that.index(thatI)\n          if (this.data(thisI) != that.data(thatI)) return false;\n          thisI += 1;\n          thatI += 1;\n        }\n      }\n      while (thisI < this.used) {\n        if (this.data(thisI) != that.default) return false;\n        thisI += 1;\n      }\n      while (thatI < that.used) {\n        if (that.data(thatI) != this.default) return false;\n        thatI += 1;\n      }\n      true;\n    case _ => false;\n  }\n}\n\nobject SparseArray extends SparseArrayOps {\n  def apply[@specialized T:ClassManifest:DefaultArrayValue](values : T*) = {\n    val rv = new SparseArray[T](values.length);\n    var i = 0;\n    for (v <- values) {\n      rv(i) = v;\n      i += 1;\n    }\n    rv.compact;\n    rv;\n  }\n\n  /**\n   * Creates a SparseArray filled with the given value.  The value function\n   * is called once initially to test if the returned value is equal to the\n   * DefaultArrayValue - if so, an empty SparseArray with initialActiveLength\n   * non-zero entries is returned.  Otherwise, an inefficient \"dense\"\n   * SparseArray is returned.\n   *\n   * @author dramage\n   */\n  def fill[@specialized T:ClassManifest:DefaultArrayValue](length : Int, initialActiveLength : Int = 3)(value : =>T) : SparseArray[T] = {\n    if (value != implicitly[DefaultArrayValue[T]].value) {\n      val rv = new SparseArray[T](length = length, initialActiveLength = length);\n      var i = 0;\n      while (i < length) {\n        rv(i) = value;\n        i += 1;\n      }\n      rv;\n    } else {\n      new SparseArray[T](length = length, initialActiveLength = length);\n    }\n  }\n\n  def create[@specialized T:ClassManifest:DefaultArrayValue](length : Int)(values : (Int,T)*) = {\n    val rv = new SparseArray[T](length = length, initialActiveLength = values.length);\n    for ((k,v) <- values) {\n      rv(k) = v;\n    }\n    rv;\n  }\n\n  def tabulate[@specialized T:ClassManifest:DefaultArrayValue](length : Int, initialActiveLength : Int = 3)(fn : (Int => T)) = {\n    val rv = new SparseArray[T](length = length, initialActiveLength = initialActiveLength);\n    var i = 0;\n    while (i < length) {\n      val v = fn(i);\n      if (v != rv.default) {\n        rv(i) = v;\n      }\n      i += 1;\n    }\n    rv.compact;\n    rv;\n  }\n  \n  class RichSparseArray[V](override val repr : SparseArray[V])\n  extends MutableNumericOps[SparseArray[V]];\n  \n  implicit def richSparseArray[V](repr : SparseArray[V]) =\n    new RichSparseArray(repr);\n  \n}\n\ntrait LowerPrioritySparseArrayOps {\n  /** Set sparse array with corresponding values from another array. */\n  implicit def OpSetSparseArraySparseArrayCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[SparseArray[V1],SparseArray[V2],OpSet]\n  = new BinaryUpdateOp[SparseArray[V1],SparseArray[V2],OpSet] {\n    def opType = OpSet;\n    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n      var i = 0;\n      while (i < a.length) {\n        a(i) = cast(b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set sparse array with casted corresponding values from another array. */\n  implicit def OpSetSparseArrayArrayCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[SparseArray[V1],Array[V2],OpSet]\n  = new BinaryUpdateOp[SparseArray[V1],Array[V2],OpSet] {\n    def opType = OpSet;\n    def apply(a : SparseArray[V1], b : Array[V2]) = {\n      var i = 0;\n      while (i < a.length) {\n        a(i) = cast(b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set array to casted scalar. */\n  implicit def OpSetSparseArrayScalarCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[SparseArray[V1],V2,OpSet]\n  = new BinaryUpdateOp[SparseArray[V1],V2,OpSet] {\n    def opType = OpSet;\n    def apply(a : SparseArray[V1], b : V2) = { \n      val v = cast(b);\n      var i = 0;\n      while (i < a.length) {\n        a(i) = v;\n        i += 1;\n      }\n    }\n  }\n}\n\ntrait LowPrioritySparseArrayOps {\n  /** Update sparse array with corresponding values from another sparse array. */\n  implicit def OpUpdateSparseArraySparseArray[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O]\n  = new BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        a(i) = op(a(i),b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set array with corresponding values from another array. */\n  implicit def OpSetSparseArraySparseArray[V](implicit s : Scalar[V])\n  : BinaryUpdateOp[SparseArray[V],SparseArray[V],OpSet]\n  = new BinaryUpdateOp[SparseArray[V],SparseArray[V],OpSet] {\n    def opType = OpSet;\n    def apply(a : SparseArray[V], b : SparseArray[V]) = { \n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        a(i) = b(i);\n        i += 1;\n      }\n    }\n  }\n\n  /** Update sparse array with corresponding values from another array. */\n  implicit def OpUpdateSparseArrayArray[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[SparseArray[V1], Array[V2], O]\n  = new BinaryUpdateOp[SparseArray[V1], Array[V2], O] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        a(i) = op(a(i),b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set sparse array with corresponding values from another array. */\n  implicit def OpSetSparseArrayArray[V](implicit s : Scalar[V])\n  : BinaryUpdateOp[SparseArray[V],Array[V],OpSet]\n  = new BinaryUpdateOp[SparseArray[V],Array[V],OpSet] {\n    def opType = OpSet;\n    def apply(a : SparseArray[V], b : Array[V]) = { \n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        a(i) = b(i);\n        i += 1;\n      }\n    }\n  }\n  \n  /** Update sparse array with scalar. */\n  implicit def OpUpdateSparseArrayScalar[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], s : Scalar[V2])\n  : BinaryUpdateOp[SparseArray[V1], V2, O]\n  = new BinaryUpdateOp[SparseArray[V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : V2) = {\n      var i = 0;\n      while (i < a.length) {\n        a(i) = op(a(i),b);\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set sparse array with scalar. */\n  implicit def OpSetSparseArrayScalar[V](implicit s : Scalar[V], dv : DefaultArrayValue[V])\n  : BinaryUpdateOp[SparseArray[V],V,OpSet]\n  = new BinaryUpdateOp[SparseArray[V],V,OpSet] {\n    def opType = OpSet;\n    def apply(a : SparseArray[V], b : V) = {\n      if (b == dv.value) {\n        a.clear();\n      } else {\n        var i = 0;\n        while (i < a.length) {\n          a(i) = b;\n          i += 1;\n        }\n      }\n    }\n  }\n}\n\ntrait SparseArrayOps extends LowPrioritySparseArrayOps {\n\n  //\n  // UnaryOps\n  //\n  \n  implicit def UnaryOp[V,RV,O<:OpType]\n  (implicit op : UnaryOp[V,O,RV], dv : DefaultArrayValue[RV], mf : Manifest[RV])\n  : UnaryOp[SparseArray[V],O,SparseArray[RV]]\n  = new UnaryOp[SparseArray[V],O,SparseArray[RV]] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V]) =\n      a.map(op apply _);\n  }\n  \n  //\n  // BinaryOps\n  //\n  \n  implicit def BinaryOpSparseArrayScalar[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], s : Scalar[V2], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])\n  : BinaryOp[SparseArray[V1], V2, O, SparseArray[RV]]\n  = new BinaryOp[SparseArray[V1], V2, O, SparseArray[RV]] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : V2) =\n      a.map(v => op(v, b));\n  }\n  \n  implicit def BinaryOpScalarSparseArray[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], s : Scalar[V1], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])\n  : BinaryOp[V1, SparseArray[V2], O, SparseArray[RV]]\n  = new BinaryOp[V1, SparseArray[V2], O, SparseArray[RV]] {\n    def opType = op.opType;\n    def apply(a : V1, b : SparseArray[V2]) =\n      b.map(v => op(a, v));\n  }\n\n  implicit def BinaryOpSparseArraySparseArray[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])\n  : BinaryOp[SparseArray[V1],SparseArray[V2],O,SparseArray[RV]]\n  = new BinaryOp[SparseArray[V1],SparseArray[V2],O,SparseArray[RV]] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n      // TODO: optimize\n      if (try { op(a.default, b.default) == dv.value } catch { case _ => false; }) {\n        outer(a, b);\n      } else {\n        all(a, b);\n      }\n    }\n\n    /** Where both a and b have non-default values. */\n    def inner(a : SparseArray[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](a.length);\n      var aO = 0;\n      var bO = 0;\n      while (aO < a.activeLength && bO < b.activeLength) {\n        val aI = a.indexAt(aO);\n        val bI = b.indexAt(bO);\n        if (aI < bI) {\n          aO += 1;\n        } else if (bI < aI) {\n          bO += 1;\n        } else {\n          rv(aI) = op(a.valueAt(aO), b.valueAt(bO));\n          aO += 1;\n          bO += 1;\n        }\n      }\n      rv;\n    }\n      \n    /** Where either a or b has non-default values. */\n    def outer(a : SparseArray[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](a.length, scala.math.max(a.activeLength,b.activeLength));\n  \n      var aO = 0;\n      var bO = 0;\n      while (aO < a.activeLength && bO < b.activeLength) {\n        val aI = a.indexAt(aO);\n        val bI = b.indexAt(bO);\n        if (aI < bI) {\n          rv(aI) = op(a.valueAt(aO), b.default);\n          aO += 1;\n        } else if (bI < aI) {\n          rv(bI) = op(a.default, b.valueAt(bO));\n          bO += 1;\n        } else {\n          rv(aI) = op(a.valueAt(aO), b.valueAt(bO));\n          aO += 1;\n          bO += 1;\n        }\n      }\n  \n      // process unpaired remaining from a\n      while (aO < a.activeLength) {\n        val aI = a.indexAt(aO);\n        rv(aI) = op(a.valueAt(aO), b.default);\n        aO += 1;\n      }\n  \n      // process unpaired remaining from b\n      while (bO < b.activeLength) {\n        val bI = b.indexAt(bO);\n        rv(bI) = op(a.default, b.valueAt(bO));\n        bO += 1;\n      }\n  \n      rv;\n    }\n    \n    /** All values regardless of whether default or not. */\n    def all(a : SparseArray[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](a.length, a.length);\n  \n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = op(a(i),b(i));\n        i += 1;\n      }\n      rv;\n    }\n  }\n\n  implicit def BinaryOpSparseArrayArray[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2],\n   d2 : DefaultArrayValue[V2], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])\n  : BinaryOp[SparseArray[V1],Array[V2],O,SparseArray[RV]]\n  = new BinaryOp[SparseArray[V1],Array[V2],O,SparseArray[RV]] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : Array[V2]) = {\n      // TODO: optimize\n      allToSparse(a, b);\n    }\n    \n    def inner(a : SparseArray[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](a.length, a.activeLength);\n      var o = 0;\n      while (o < a.activeLength) {\n        val i = a.indexAt(o);\n        rv(i) = op(a.valueAt(o), b(i));\n        o += 1;\n      }\n      rv;\n    }\n    \n    def allToDense(a : SparseArray[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new Array[RV](a.length);\n      var i = 0;\n      while (i < a.length) {\n        rv(i) = op(a(i), b(i));\n        i += 1;\n      }\n      rv;\n    }\n    \n    def allToSparse(a : SparseArray[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](a.length, a.activeLength);\n      var i = 0;\n      while (i < a.length) {\n        rv(i) = op(a(i), b(i));\n        i += 1;\n      }\n      rv;\n    }\n  }\n\n  implicit def BinaryOpArraySparseArray[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2],\n   d1 : DefaultArrayValue[V1], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])\n  : BinaryOp[Array[V1],SparseArray[V2],O,SparseArray[RV]]\n  = new BinaryOp[Array[V1],SparseArray[V2],O,SparseArray[RV]] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : SparseArray[V2]) = {\n      // TODO: optimize\n      allToSparse(a, b);\n    }\n    \n    def inner(a : Array[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](b.length, b.activeLength);\n      var o = 0;\n      while (o < b.activeLength) {\n        val i = b.indexAt(o);\n        rv(i) = op(a(i), b.valueAt(o));\n        o += 1;\n      }\n      rv;\n    }\n    \n    def allToDense(a : Array[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new Array[RV](b.length);\n      var i = 0;\n      while (i < a.length) {\n        rv(i) = op(a(i), b(i));\n        i += 1;\n      }\n      rv;\n    }\n    \n    def allToSparse(a : Array[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"arrays have different lengths\");\n      val rv = new SparseArray[RV](b.length);\n      var i = 0;\n      while (i < a.length) {\n        rv(i) = op(a(i), b(i));\n        i += 1;\n      }\n      rv;\n    }\n  }\n\n  /** Recurse on elements within an array. */\n  implicit def BinaryUpdateOpRecurseSparseArraySparseArray[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O]\n  = new BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        op(a(i),b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Recurse on elements within an array. */\n  implicit def BinaryUpdateOpRecurseSparseArrayArray[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[SparseArray[V1], Array[V2], O]\n  = new BinaryUpdateOp[SparseArray[V1], Array[V2], O] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        op(a(i),b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Recurse on elements. */\n  implicit def BinaryUpdateOpRecurseSparseArrayScalar[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], s : Scalar[V2])\n  : BinaryUpdateOp[SparseArray[V1], V2, O]\n  = new BinaryUpdateOp[SparseArray[V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : SparseArray[V1], b : V2) = {\n      var i = 0;\n      while (i < a.length) {\n        op(a(i),b);\n        i += 1;\n      }\n    }\n  }\n  \n///**\n// * Base class for updating a SparseArray by another SparseArray.  Considers\n// * only non-zeros in the left operand.  Base class of MulInto.\n// *\n// * @author dramage\n// */\n//class SparseArraySparseArrayUpdateLeftNZOp[V1,V2](implicit op : BinaryOp[V1,V2,V1])\n//extends BinaryUpdateOp[SparseArray[V1],SparseArray[V2]] {\n//  def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n//    if (a.length != b.length) {\n//      throw new DomainException(this.getClass.getSimpleName + \": arrays have different lengths\");\n//    }\n//    var aO = 0;\n//    var bO = 0;\n//    while (aO < a.activeLength && bO < b.activeLength) {\n//      val aI = a.indexAt(aO);\n//      val bI = b.indexAt(bO);\n//      if (aI < bI) {\n//        a(aI) = op(a.valueAt(aO), b.default);\n//        aO += 1;\n//      } else if (bI < aI) {\n//        bO += 1;\n//      } else {\n//        a(aI) = op(a.valueAt(aO), b.valueAt(bO));\n//        aO += 1;\n//        bO += 1;\n//      }\n//    }\n//\n//    // process unpaired remaining from a\n//    while (aO < a.activeLength) {\n//      val aI = a.indexAt(aO);\n//      a(aI) = op(a.valueAt(aO), b.default);\n//      aO += 1;\n//    }\n//  }\n//}\n//\n///**\n// * Base class for updating a SparseArray by another SparseArray.  Considers\n// * non-zeros in either operand.  Base class of AddInto.\n// *\n// * @author dramage\n// */\n//class SparseArraySparseArrayUpdateEitherNZOp[V1,V2](implicit op : BinaryOp[V1,V2,V1])\n//extends BinaryUpdateOp[SparseArray[V1],SparseArray[V2]] {\n//  def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n//    if (a.length != b.length) {\n//      throw new DomainException(this.getClass.getSimpleName + \": arrays have different lengths\");\n//    }\n//    \n//    var aO = 0;\n//    var bO = 0;\n//    while (aO < a.activeLength && bO < b.activeLength) {\n//      val aI = a.indexAt(aO);\n//      val bI = b.indexAt(bO);\n//      if (aI < bI) {\n//        a(aI) = op(a.valueAt(aO), b.default);\n//        aO += 1;\n//      } else if (bI < aI) {\n//        a(bI) = op(a.default, b.valueAt(bO));\n//        bO += 1;\n//      } else {\n//        a(aI) = op(a.valueAt(aO), b.valueAt(bO));\n//        aO += 1;\n//        bO += 1;\n//      }\n//    }\n//    \n//    // process unpaired remaining from a\n//    while (aO < a.activeLength) {\n//      val aI = a.indexAt(aO);\n//      a(aI) = op(a.valueAt(aO), b.default);\n//      aO += 1;\n//    }\n//\n//    // process unpaired remaining from b\n//    while (bO < b.activeLength) {\n//      val bI = b.indexAt(bO);\n//      a(bI) = op(a.default, b.valueAt(bO));\n//      bO += 1;\n//    }\n//  }\n//}\n//\n///**\n// * Base class for updating a SparseArray by another SparseArray.  Considers\n// * all values.  Base class of DivInto.\n// *\n// * @author dramage\n// */\n//class SparseArraySparseArrayUpdateAllOp[V1,V2](implicit op : BinaryOp[V1,V2,V1])\n//extends BinaryUpdateOp[SparseArray[V1],SparseArray[V2]] {\n//  def apply(a : SparseArray[V1], b : SparseArray[V2]) = {\n//    if (a.length != b.length) {\n//      throw new DomainException(this.getClass.getSimpleName + \": arrays have different lengths\");\n//    }\n//\n//    /** Optimization: use OuterOp if the default value is itself default */\n//    if (try { op(a.default, b.default) == a.default } catch { case _ => false; }) {\n//      (new SparseArraySparseArrayUpdateEitherNZOp[V1,V2]).apply(a,b);\n//    } else {\n//      var i = 0;\n//      while (i < a.length) {\n//        a(i) = op(a(i),b(i));\n//        i += 1;\n//      }\n//    }\n//  }\n//}\n//\n//class SparseArrayScalarUpdateOp[V1,B](implicit op : BinaryOp[V1,B,V1], sb : Scalar[B])\n//extends BinaryUpdateOp[SparseArray[V1],B] {\n//  def apply(a : SparseArray[V1], b : B) =\n//    a.transform(v => op(v, b));\n//}\n}\n\n\n/**\n * Default value of type T as used by SparseArray.\n * \n * Note that this is not the same as a general default value for T,\n * say as used by DomainMap, because this value must be null for\n * all references types in order for SparseArray to work as expected.\n * \n * @author dramage\n */\nsealed trait DefaultArrayValue[@specialized T] extends Serializable {\n  def value : T;\n}\n\nobject DefaultArrayValue {\n  implicit object IntDefaultArrayValue extends DefaultArrayValue[Int] {\n    override def value = 0;\n  }\n\n  implicit object ShortDefaultArrayValue extends DefaultArrayValue[Short] {\n    override def value = 0.toShort;\n  }\n\n  implicit object LongDefaultArrayValue extends DefaultArrayValue[Long] {\n    override def value = 0l;\n  }\n\n  implicit object ByteDefaultArrayValue extends DefaultArrayValue[Byte] {\n    override def value = 0.toByte;\n  }\n\n  implicit object CharDefaultArrayValue extends DefaultArrayValue[Char] {\n    override def value = 0.toChar;\n  }\n\n  implicit object FloatDefaultArrayValue extends DefaultArrayValue[Float] {\n    override def value = 0.0f;\n  }\n\n  implicit object DoubleDefaultArrayValue extends DefaultArrayValue[Double] {\n    override def value = 0.0;\n  }\n\n  implicit object BooleanDefaultArrayValue extends DefaultArrayValue[Boolean] {\n    override def value = false;\n  }\n\n  val refDefault = new DefaultArrayValue[AnyRef] {\n    override def value : AnyRef = null;\n  }\n\n  implicit def ObjectDefaultArrayValue[T<:AnyRef] =\n    refDefault.asInstanceOf[DefaultArrayValue[T]];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanAppendColumns.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.scalar._;\nimport scalala.tensor.domain.DomainException;\nimport scalala.collection.sparse.{SparseArray,DefaultArrayValue};\n\n/**\n * Construction delegate for appending columns with A | B.\n *\n * @author dramage\n */\ntrait CanAppendColumns[A,-B,+That] extends Function2[A,B,That];\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanBuildTensorForBinaryOp.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.tensor.domain.CanGetDomain;\nimport scalala.tensor.generic.TensorBuilder;\nimport scalala.tensor.Tensor;\n\n/**\n * Trait for building a new tensor from either A or B depending on the\n * given Op.  Default to building tensor for left operand.\n *\n * @author dramage\n */\ntrait CanBuildTensorForBinaryOp[-A, -B, D, K, V, Op, +To] {\n  def apply(a : A, b : B, domain : D) : TensorBuilder[K,V,To];\n}\n\nobject CanBuildTensorForBinaryOp {\n  implicit def canBuildTensorLeft[A,B,D,K,V,Op,To]\n  (implicit va : A=>Tensor[_,_], bf : CanBuildTensorFrom[A,D,K,V,To])\n  : CanBuildTensorForBinaryOp[A,B,D,K,V,Op,To]\n  = new CanBuildTensorForBinaryOp[A,B,D,K,V,Op,To] {\n    def apply(a : A, b : B, domain : D)  = bf.apply(a, domain);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanBuildTensorFrom.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.tensor._;\nimport scalala.tensor.domain._;\nimport scalala.tensor.dense._;\nimport scalala.tensor.generic.TensorBuilder;\nimport scalala.scalar.Scalar;\n\n/**\n * Trait for constructing a lazy view of a given Tensor.\n *\n * @author dramage\n */\ntrait CanBuildTensorFrom[-From, -Domain, K, V, +To] {\n  def apply(from : From, domain : Domain) : TensorBuilder[K,V,To];\n}\n\n/**\n * Base level implicits take any tensor and any domain.\n *\n * @author dramage\n */\ntrait CanBuildTensorFromImplicitsLevel0 {\n  implicit def canBuildTensorFromTensor[K,V:Scalar]\n  : CanBuildTensorFrom[Tensor[_,_], IterableDomain[K], K, V, mutable.Tensor[K,V]]\n  = new CanBuildTensorFrom[Tensor[_,_], IterableDomain[K], K, V, mutable.Tensor[K,V]] {\n    override def apply(from : Tensor[_,_], domain : IterableDomain[K]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Tensor[K,V]]];\n  }\n}\n\n/**\n * Implicits that take any shaped tensor (Tensor1Row, Tensor1Col, Tensor2)\n * and a shaped domain and return a similarly shaped tensor.\n *\n * @author dramage\n */\ntrait CanBuildTensorFromImplicitsLevel1 extends CanBuildTensorFromImplicitsLevel0 {\n  implicit def canBuildTensor1RowFromTensor1Row[K,V:Scalar]\n  : CanBuildTensorFrom[Tensor1Row[_,_], Domain1[K], K, V, mutable.Tensor1Row[K,V]]\n  = new CanBuildTensorFrom[Tensor1Row[_,_], Domain1[K], K, V, mutable.Tensor1Row[K,V]] {\n    override def apply(from : Tensor1Row[_,_], domain : Domain1[K]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Tensor1Row[K,V]]];\n  }\n  \n  implicit def canBuildTensor1ColFromTensor1Row[K,V:Scalar]\n  : CanBuildTensorFrom[Tensor1Col[_,_], Domain1[K], K, V, mutable.Tensor1Col[K,V]]\n  = new CanBuildTensorFrom[Tensor1Col[_,_], Domain1[K], K, V, mutable.Tensor1Col[K,V]] {\n    override def apply(from : Tensor1Col[_,_], domain : Domain1[K]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Tensor1Col[K,V]]];\n  }\n\n  implicit def canBuildTensor2FromTensor[K1,K2,V:Scalar]\n  : CanBuildTensorFrom[Tensor[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Tensor2[K1,K2,V]]\n  = new CanBuildTensorFrom[Tensor[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Tensor2[K1,K2,V]] {\n    override def apply(from : Tensor[_,_], domain : Domain2[K1,K2]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[(K1,K2),V,mutable.Tensor2[K1,K2,V]]];\n  }\n}\n\n/**\n * Implicits that take any tensor and a vector/matrix domain and return a\n * vector or matrix.\n *\n * @author dramage\n */\ntrait CanBuildTensorFromImplicitsLevel2 extends CanBuildTensorFromImplicitsLevel1 {\n  implicit def canBuildVectorColFromTensor[V:Scalar]\n  : CanBuildTensorFrom[Tensor[_,_], IndexDomain, Int, V, mutable.VectorCol[V]]\n  = new CanBuildTensorFrom[Tensor[_,_], IndexDomain, Int, V, mutable.VectorCol[V]] {\n    override def apply(from : Tensor[_,_], domain : IndexDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,mutable.VectorCol[V]]];\n  }\n  \n  implicit def canBuildMatrixFromTensor[V:Scalar]\n  : CanBuildTensorFrom[Tensor[_,_], TableDomain, (Int,Int), V, mutable.Matrix[V]]\n  = new CanBuildTensorFrom[Tensor[_,_], TableDomain, (Int,Int), V, mutable.Matrix[V]] {\n    override def apply(from : Tensor[_,_], domain : TableDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[(Int,Int),V,mutable.Matrix[V]]];\n  }\n}\n\n/**\n * Keep row shape in Level 2.\n *\n * @author dramage\n */\ntrait CanBuildTensorFromImplicitsLevel2Row extends CanBuildTensorFromImplicitsLevel2 {\n  implicit def canBuildVectorRowFromTensor1Row[V:Scalar]\n  : CanBuildTensorFrom[Tensor1Row[_,_], IndexDomain, Int, V, mutable.VectorRow[V]]\n  = new CanBuildTensorFrom[Tensor1Row[_,_], IndexDomain, Int, V, mutable.VectorRow[V]] {\n    override def apply(from : Tensor1Row[_,_], domain : IndexDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,mutable.VectorRow[V]]];\n  }\n}\n\n/**\n * Implicits that keep the type and shape of common input vectors and matrices.\n *\n * @author dramage\n */\ntrait CanBuildTensorFromImplicitsLevel3 extends CanBuildTensorFromImplicitsLevel2Row {\n  import dense._;\n  import sparse._;\n  import tensor.{Counter,Counter2};\n\n  implicit def canBuildCounterFromCounter[K,V:Scalar]\n  : CanBuildTensorFrom[Counter[_,_], Domain1[K], K, V, mutable.Counter[K,V]]\n  = new CanBuildTensorFrom[Counter[_,_], Domain1[K], K, V, mutable.Counter[K,V]] {\n    override def apply(from : Counter[_,_], domain : Domain1[K]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Counter[K,V]]];\n  }\n  \n  implicit def canBuildCounter2FromCounter2[K1,K2,V:Scalar]\n  : CanBuildTensorFrom[Counter2[_,_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]]\n  = new CanBuildTensorFrom[Counter2[_,_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]] {\n    override def apply(from : Counter2[_,_,_], domain : Domain2[K1,K2]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[(K1,K2),V,mutable.Counter2[K1,K2,V]]];\n  }\n  \n  implicit def canBuildCounterFromCounter2[K,V:Scalar]\n  : CanBuildTensorFrom[Counter2[_,_,_], Domain1[K], K, V, mutable.Counter[K,V]]\n  = new CanBuildTensorFrom[Counter2[_,_,_], Domain1[K], K, V, mutable.Counter[K,V]] {\n    override def apply(from : Counter2[_,_,_], domain : Domain1[K]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Counter[K,V]]];\n  }\n  \n  implicit def canBuildCounter2FromCounter[K1,K2,V:Scalar]\n  : CanBuildTensorFrom[Counter[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]]\n  = new CanBuildTensorFrom[Counter[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]] {\n    override def apply(from : Counter[_,_], domain : Domain2[K1,K2]) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[(K1,K2),V,mutable.Counter2[K1,K2,V]]];\n  }\n  \n  implicit def canBuildDenseVectorColFromDenseTensor[V:Scalar]\n  : CanBuildTensorFrom[DenseArrayTensor[_,_], IndexDomain, Int, V, DenseVectorCol[V]]\n  = new CanBuildTensorFrom[DenseArrayTensor[_,_], IndexDomain, Int, V, DenseVectorCol[V]] {\n    override def apply(from : DenseArrayTensor[_,_], domain : IndexDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,DenseVectorCol[V]]];\n  }\n  \n  implicit def canBuildDenseMatrixFromDenseTensor[V:Scalar]\n  : CanBuildTensorFrom[DenseArrayTensor[_,_], TableDomain, (Int,Int), V, DenseMatrix[V]]\n  = new CanBuildTensorFrom[DenseArrayTensor[_,_], TableDomain, (Int,Int), V, DenseMatrix[V]] {\n    override def apply(from : DenseArrayTensor[_,_], domain : TableDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[(Int,Int),V,DenseMatrix[V]]];\n  }\n  \n  implicit def canBuildSparseVectorColFromSparseTensor[V:Scalar]\n  : CanBuildTensorFrom[SparseArrayTensor[_,_], IndexDomain, Int, V, SparseVectorCol[V]]\n  = new CanBuildTensorFrom[SparseArrayTensor[_,_], IndexDomain, Int, V, SparseVectorCol[V]] {\n    override def apply(from : SparseArrayTensor[_,_], domain : IndexDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,SparseVectorCol[V]]];\n  }\n}\n\n/**\n * Keep row shape in Level 3.\n *\n * @author dramage\n */\ntrait CanBuildTensorFromImplicitsLevel3Row extends CanBuildTensorFromImplicitsLevel3 {\n  import dense._;\n  import sparse._;\n\n  implicit def canBuildDenseVectorRowFromDenseVectorRow[V:Scalar]\n  : CanBuildTensorFrom[DenseVectorRow[_], IndexDomain, Int, V, DenseVectorRow[V]]\n  = new CanBuildTensorFrom[DenseVectorRow[_], IndexDomain, Int, V, DenseVectorRow[V]] {\n    override def apply(from : DenseVectorRow[_], domain : IndexDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,DenseVectorRow[V]]];\n  }\n\n  implicit def canBuildSparseVectorRowFromSparseVectorRow[V:Scalar]\n  : CanBuildTensorFrom[SparseVectorRow[_], IndexDomain, Int, V, SparseVectorRow[V]]\n  = new CanBuildTensorFrom[SparseVectorRow[_], IndexDomain, Int, V, SparseVectorRow[V]] {\n    override def apply(from : SparseVectorRow[_], domain : IndexDomain) =\n      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,SparseVectorRow[V]]];\n  }\n}\n\nobject CanBuildTensorFrom extends CanBuildTensorFromImplicitsLevel3Row;\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanCopy.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n\nimport scalala.scalar.Scalar;\n\n/**\n * Marker for being able to copy a collection\n *\n * @author dlwh\n */\ntrait CanCopy[T] {\n  // Should not inherit from T=>T because those get  used by the compiler.\n  def apply(t: T):T\n}\n\nobject CanCopy {\n\n  class OpArray[@specialized V:ClassManifest:Scalar]\n  extends CanCreateZerosLike[Array[V],Array[V]] {\n    override def apply(from : Array[V]) = {\n      Array.fill(from.length)(implicitly[Scalar[V]].zero);\n    }\n  }\n\n  class OpMapValues[From,A](implicit op : CanCopy[A], map : CanMapValues[From,A,A,From]) extends CanCopy[From] {\n    def apply(v : From) = map.map(v, op.apply(_));\n  }\n\n  implicit def opMapValues[From,A](implicit map : CanMapValues[From,A,A,From], op : CanCopy[A])\n  : CanCopy[From] = new OpMapValues[From,A]()(op, map);\n\n  implicit def OpArrayAny[V:ClassManifest:Scalar] : OpArray[V] =\n    new OpArray[V];\n\n  implicit object OpArrayI extends OpArray[Int];\n  implicit object OpArrayS extends OpArray[Short];\n  implicit object OpArrayL extends OpArray[Long];\n  implicit object OpArrayF extends OpArray[Float];\n  implicit object OpArrayD extends OpArray[Double];\n\n  implicit def canCopyScalar[V:Scalar]:CanCopy[V] = new CanCopy[V] {\n    def apply(v1: V) = v1;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanCreateZerosLike.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.collection.sparse.{SparseArray,DefaultArrayValue};\nimport scalala.scalar.Scalar;\n\n/**\n * Marker for being able to create a collection of the same shape as\n * the given input but with zero values everywhere.\n *\n * @author dramage\n */\ntrait CanCreateZerosLike[-From, +To] {\n  // Should not inherit from Form=>To because the compiler will try to use it to coerce types.\n  def apply(from: From):To\n};\n\nobject CanCreateZerosLike {\n\n  class OpArray[@specialized V:ClassManifest:Scalar]\n  extends CanCreateZerosLike[Array[V],Array[V]] {\n    override def apply(from : Array[V]) = {\n      Array.fill(from.length)(implicitly[Scalar[V]].zero);\n    }\n  }\n\n  class OpMapValues[From,A,To](implicit op : Scalar[A], map : CanMapValues[From,A,A,To]) extends CanCreateZerosLike[From,To] {\n    def apply(v : From) = map.map(v, _ => op.zero);\n  }\n\n  implicit def opMapValues[From,A,To](implicit map : CanMapValues[From,A,A,To], op : Scalar[A])\n  : CanCreateZerosLike[From,To] = new OpMapValues[From,A,To]()(op, map);\n\n  implicit def OpArrayAny[V:ClassManifest:Scalar] : OpArray[V] =\n    new OpArray[V];\n\n  implicit object OpArrayI extends OpArray[Int];\n  implicit object OpArrayS extends OpArray[Short];\n  implicit object OpArrayL extends OpArray[Long];\n  implicit object OpArrayF extends OpArray[Float];\n  implicit object OpArrayD extends OpArray[Double];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanFilterValues.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.collection.sparse.{SparseArray,DefaultArrayValue};\n\n/**\n * Marker for being able to filter the values in a value collection.\n *\n * @author dramage\n */\ntrait CanFilterValues[From, @specialized A, +To] {\n  /** Maps all values from the given collection. */\n  def filter(from : From, fn : (A=>Boolean)) : To;\n\n  /** Maps all non-zero values from the given collection. */\n  def filterNonZero(from : From, fn : (A=>Boolean)) : To;\n}\n\nobject CanFilterValues {\n  type Op[From,A,To] = CanFilterValues[From,A,To];\n\n  //\n  // Arrays\n  //\n\n  class OpArray[@specialized A:ClassManifest]\n  extends Op[Array[A],A,Array[A]] {\n    def filter(from : Array[A], fn : (A=>Boolean)) =\n      from.filter(fn);\n    def filterNonZero(from : Array[A], fn : (A => Boolean)) =\n      this.filter(from, fn);\n  }\n\n  implicit def opArray[@specialized A:ClassManifest] =\n    new OpArray[A];\n\n  implicit object OpArrayI extends OpArray[Int];\n  implicit object OpArrayS extends OpArray[Short];\n  implicit object OpArrayL extends OpArray[Long];\n  implicit object OpArrayF extends OpArray[Float];\n  implicit object OpArrayD extends OpArray[Double];\n\n  //\n  // SparseArrays\n  //\n  class OpSparseArray[@specialized V:ClassManifest:DefaultArrayValue]\n  extends Op[SparseArray[V],V,SparseArray[V]] {\n    def filter(from : SparseArray[V], fn : (V=>Boolean)) =\n      from.filter(fn);\n\n    def filterNonZero(from : SparseArray[V], fn : (V=>Boolean)) = {\n      val rv = new SparseArray[V](from.length, from.activeLength);\n      from.foreachActivePair((k,v) => if (fn(v)) { rv(k) = v; });\n      rv.compact;\n      rv;\n    }\n  }\n\n  implicit def opSparseArray[@specialized V:ClassManifest:DefaultArrayValue] =\n    new OpSparseArray[V];\n\n  implicit object OpSparseArrayI extends OpSparseArray[Int];\n  implicit object OpSparseArrayS extends OpSparseArray[Short];\n  implicit object OpSparseArrayL extends OpSparseArray[Long];\n  implicit object OpSparseArrayF extends OpSparseArray[Float];\n  implicit object OpSparseArrayD extends OpSparseArray[Double];\n\n\n  //\n  // Scala maps\n  //\n\n  implicit def opMap[A, B, That](implicit bf : scala.collection.generic.CanBuildFrom[scala.collection.Map[A,B], (A,B), That]) =\n    new OpMap[A,B,That];\n\n  class OpMap[A, B, That] extends Op[scala.collection.Map[A,B],B,scala.collection.Map[A,B]] {\n    def filter(from : scala.collection.Map[A,B], fn : (B => Boolean)) =\n      from.filter((tup : (A,B)) => fn(tup._2));\n    def filterNonZero(from : scala.collection.Map[A,B], fn : (B => Boolean)) =\n      this.filter(from, fn);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanGetActiveValues.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.collection.sparse.SparseArray;\n\n/**\n * Marker for being able to get the domain (keys) of a collection.\n *\n * @author dramage\n */\ntrait CanGetActiveValues[-Coll, @specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V] {\n  def apply(coll : Coll) : Iterator[(K,V)];\n}\n\nobject CanGetActiveValues {\n  class OpArray[V] extends CanGetActiveValues[Array[V],Int,V] {\n    override def apply(coll : Array[V]) =\n      Iterator.range(0, coll.length).map(i => (i, coll(i)));\n  }\n\n  implicit def opArray[V] = new OpArray[V];\n\n  implicit object OpArrayI extends OpArray[Int];\n  implicit object OpArrayS extends OpArray[Short];\n  implicit object OpArrayL extends OpArray[Long];\n  implicit object OpArrayF extends OpArray[Float];\n  implicit object OpArrayD extends OpArray[Double];\n\n  class OpSparseArray[V] extends CanGetActiveValues[SparseArray[V],Int,V] {\n    override def apply(coll : SparseArray[V]) =\n      coll.activeIterator;\n  }\n\n  implicit def opSparseArray[V] = new OpSparseArray[V];\n  \n  implicit object OpSparseArrayI extends OpSparseArray[Int];\n  implicit object OpSparseArrayS extends OpSparseArray[Short];\n  implicit object OpSparseArrayL extends OpSparseArray[Long];\n  implicit object OpSparseArrayF extends OpSparseArray[Float];\n  implicit object OpSparseArrayD extends OpSparseArray[Double];\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanGetDouble.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Marker for being able to get the value of a map at a key as a double.\n *\n * @author dramage\n */\ntrait CanGetDouble[-Coll, @specialized(Int,Long) -K] {\n  def apply(coll : Coll, key : K) : Double;\n}\n\nobject CanGetDouble {\n  type Op[Coll,K] = CanGetDouble[Coll,K];\n\n  implicit object OpArrayI extends Op[Array[Int],Int]\n  { override def apply(coll : Array[Int], key : Int) = coll(key); }\n\n  implicit object OpArrayS extends Op[Array[Short],Int]\n  { override def apply(coll : Array[Short], key : Int) = coll(key); }\n\n  implicit object OpArrayL extends Op[Array[Long],Int]\n  { override def apply(coll : Array[Long], key : Int) = coll(key); }\n\n  implicit object OpArrayF extends Op[Array[Float],Int]\n  { override def apply(coll : Array[Float], key : Int) = coll(key); }\n\n  implicit object OpArrayD extends Op[Array[Double],Int]\n  { override def apply(coll : Array[Double], key : Int) = coll(key); }\n\n  implicit def opIndexedSeq[@specialized V](implicit cv : V => Double) =\n    new OpIndexedSeq[V];\n\n  class OpIndexedSeq[@specialized V](implicit cv : V => Double) extends CanGetDouble[IndexedSeq[V], Int] {\n    def apply(coll : IndexedSeq[V], key : Int) = coll(key);\n  }\n\n  implicit object OpIndexedSeqI extends OpIndexedSeq[Int];\n  implicit object OpIndexedSeqC extends OpIndexedSeq[Char];\n  implicit object OpIndexedSeqS extends OpIndexedSeq[Short];\n  implicit object OpIndexedSeqL extends OpIndexedSeq[Long];\n  implicit object OpIndexedSeqF extends OpIndexedSeq[Float];\n  implicit object OpIndexedSeqD extends OpIndexedSeq[Double];\n\n  implicit def opMap[K,V](implicit cv : V => Double) =\n    new OpMap[K,V];\n\n  class OpMap[K,V](implicit cv : V => Double) extends CanGetDouble[scala.collection.Map[K,V], K] {\n    def apply(coll : scala.collection.Map[K,V], key : K) = coll(key);\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanGetValue.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Marker for being able to get the value of a map at a key.\n *\n * @author dramage\n */\ntrait CanGetValue[-Coll, @specialized(Int,Long) -K, @specialized(Int,Long,Float,Double) +V] {\n  def apply(coll : Coll, key : K) : V;\n}\n\nobject CanGetValue {\n  implicit def opArray[@specialized V] =\n    new OpArray[V];\n\n  class OpArray[@specialized V] extends CanGetValue[Array[V], Int, V] {\n    def apply(coll : Array[V], key : Int) = coll(key);\n  }\n\n  implicit object OpArrayI extends OpArray[Int];\n  implicit object OpArrayC extends OpArray[Char];\n  implicit object OpArrayS extends OpArray[Short];\n  implicit object OpArrayL extends OpArray[Long];\n  implicit object OpArrayF extends OpArray[Float];\n  implicit object OpArrayD extends OpArray[Double];\n  implicit object OpArrayB extends OpArray[Boolean];\n\n  implicit def opIndexedSeq[@specialized V] =\n    new OpIndexedSeq[V];\n\n  class OpIndexedSeq[@specialized V] extends CanGetValue[IndexedSeq[V], Int, V] {\n    def apply(coll : IndexedSeq[V], key : Int) = coll(key);\n  }\n\n  implicit object OpIndexedSeqI extends OpIndexedSeq[Int];\n  implicit object OpIndexedSeqC extends OpIndexedSeq[Char];\n  implicit object OpIndexedSeqS extends OpIndexedSeq[Short];\n  implicit object OpIndexedSeqL extends OpIndexedSeq[Long];\n  implicit object OpIndexedSeqF extends OpIndexedSeq[Float];\n  implicit object OpIndexedSeqD extends OpIndexedSeq[Double];\n  implicit object OpIndexedSeqB extends OpIndexedSeq[Boolean];\n\n  implicit def opMap[K,V] =\n    new OpMap[K,V];\n\n  class OpMap[K,V] extends CanGetValue[scala.collection.Map[K,V], K, V] {\n    def apply(coll : scala.collection.Map[K,V], key : K) = coll(key);\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanJoin.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Trait for applying a function to two tensors across their underlying\n * shared keys -- either all keys or non-zero keys.  The tensors must\n * have the same domain.\n *\n * @author dramage\n */\ntrait CanJoin[-A, -B, @specialized(Int,Long) K,\n              @specialized(Int,Long,Float,Double) V1,\n              @specialized(Int,Long,Float,Double) V2] {\n  /** Joins on all keys in the domain. */\n  def joinAll[RV](a : A, b : B, fn : (K,V1,V2)=>RV) : Unit;\n\n  /** Joins when both a and b are non-zero. */\n  def joinBothNonZero[RV](a : A, b : B, fn : (K,V1,V2)=>RV) : Unit;\n\n  /** Joins when either a or b is non-zero. */\n  def joinEitherNonZero[RV](a : A, b : B, fn : (K,V1,V2)=>RV) : Unit;\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanMapKeyValuePairs.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Marker for being able to map the keys and values in a value collection\n * to new values.\n *\n * @author dramage\n */\ntrait CanMapKeyValuePairs[-From, +K, +A, -B, +To] {\n  /** Maps all key-value pairs from the given collection. */\n  def map(from : From, fn : ((K,A) => B)) : To;\n\n  /** Maps all non-zero key-value pairs from the given collection. */\n  def mapNonZero(from : From, fn : ((K,A) => B)) : To;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanMapValues.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.scalar.Complex\nimport scalala.collection.sparse.{SparseArray,DefaultArrayValue};\n\n/**\n * Marker for being able to map the values in a value collection.\n *\n * @author dramage\n */\ntrait CanMapValues[From, @specialized A, @specialized B, +To] {\n  /** Maps all values from the given collection. */\n  def map(from : From, fn : (A=>B)) : To;\n\n  /** Maps all non-zero values from the given collection. */\n  def mapNonZero(from : From, fn : (A=>B)) : To;\n}\n\nobject CanMapValues {\n  type Op[From,A,B,To] = CanMapValues[From,A,B,To];\n\n  //\n  // Arrays\n  //\n\n  class OpArray[@specialized A, @specialized B:ClassManifest]\n  extends Op[Array[A],A,B,Array[B]] {\n    def map(from : Array[A], fn : (A=>B)) =\n      from.map(fn);\n    def mapNonZero(from : Array[A], fn : (A => B)) =\n      this.map(from, fn);\n  }\n\n  implicit def opArray[@specialized A, @specialized B:ClassManifest] =\n    new OpArray[A,B];\n\n  implicit object OpArrayII extends OpArray[Int,Int];\n  implicit object OpArraySS extends OpArray[Short,Short];\n  implicit object OpArrayLL extends OpArray[Long,Long];\n  implicit object OpArrayFF extends OpArray[Float,Float];\n  implicit object OpArrayDD extends OpArray[Double,Double];\n  implicit object OpArrayCC extends OpArray[Complex,Complex];\n  implicit object OpArrayID extends OpArray[Int,Double];\n  implicit object OpArraySD extends OpArray[Short,Double];\n  implicit object OpArrayLD extends OpArray[Long,Double];\n  implicit object OpArrayFD extends OpArray[Float,Double];\n\n  //\n  // SparseArrays\n  //\n\n  class OpSparseArray[@specialized V, @specialized RV:ClassManifest:DefaultArrayValue]\n  extends Op[SparseArray[V],V,RV,SparseArray[RV]] {\n    def map(from : SparseArray[V], fn : (V=>RV)) =\n      from.map(fn);\n\n    def mapNonZero(from : SparseArray[V], fn : (V => RV)) = {\n      val rv = new SparseArray[RV](from.length, from.activeLength);\n      from.foreachActivePair((k,v) => rv(k) = fn(v));\n      rv;\n    }\n  }\n\n  implicit def opSparseArray[@specialized V, @specialized RV:ClassManifest:DefaultArrayValue] =\n    new OpSparseArray[V,RV];\n\n  implicit object OpSparseArrayII extends OpSparseArray[Int,Int];\n  implicit object OpSparseArraySS extends OpSparseArray[Short,Short];\n  implicit object OpSparseArrayLL extends OpSparseArray[Long,Long];\n  implicit object OpSparseArrayFF extends OpSparseArray[Float,Float];\n  implicit object OpSparseArrayDD extends OpSparseArray[Double,Double];\n  implicit object OpSparseArrayCC extends OpSparseArray[Complex,Complex];\n  implicit object OpSparseArrayID extends OpSparseArray[Int,Double];\n  implicit object OpSparseArraySD extends OpSparseArray[Short,Double];\n  implicit object OpSparseArrayLD extends OpSparseArray[Long,Double];\n  implicit object OpSparseArrayFD extends OpSparseArray[Float,Double];\n\n  //\n  // Scala maps\n  //\n\n  implicit def opMap[A, B, O, That](implicit bf : scala.collection.generic.CanBuildFrom[scala.collection.Map[A,B], (A,O), That]) =\n    new OpMap[A,B,O,That];\n\n  class OpMap[K, A, B, That](implicit bf : scala.collection.generic.CanBuildFrom[scala.collection.Map[K,A], (K,B), That])\n  extends Op[scala.collection.Map[K,A],A,B,That] {\n    def map(from : scala.collection.Map[K,A], fn : (A => B)) =\n      from.map(tup => (tup._1, fn(tup._2)));\n    def mapNonZero(from : scala.collection.Map[K,A], fn : (A => B)) =\n      this.map(from, fn);\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanSliceMatrix.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Builder trait for a slicing a view of a matrix.\n *\n * @author dramage\n */\ntrait CanSliceMatrix[-From, A1, A2, +To] {\n  def apply(from : From, keys1 : Seq[A1], keys2 : Seq[A2]) : To;\n}\n\n\n/**\n * Builder trait for a slicing a row from a matrix.\n *\n * @author dramage\n */\ntrait CanSliceRow[-From, K, +To] {\n  def apply(from : From, row : K) : To;\n}\n\n\n/**\n * Builder trait for a slicing a column from a matrix.\n *\n * @author dramage\n */\ntrait CanSliceCol[-From, K, +To] {\n  def apply(from : From, col : K) : To;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanSliceTensor.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Supports sliced view of a Tensor.\n *\n * @author dramage\n */\ntrait CanSliceTensor[-From, A1, A2, +To] {\n  def apply(from : From, keymap : scala.collection.Map[A2,A1]) : To;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanSliceVector.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Capability trait for slicing a Vector from something.\n *\n * @author dramage\n */\ntrait CanSliceVector[-From, A, +To] {\n  def apply(from : From, keys : Seq[A]) : To;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanTranspose.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scalala.tensor._;\n\n/**\n * Transpose of a shaped value.\n *\n * @author dramage\n */\ntrait CanTranspose[-From,+To] extends (From=>To);\n\n/**\n * Transpose non-mutable tensors.\n * \n * @author dramage\n */\ntrait CanTransposeImplicitsLevel0 {\n  implicit def canTransposeTensor1Row[K,V]\n  : CanTranspose[Tensor1Row[K,V],Tensor1Col[K,V]]\n  = new CanTranspose[Tensor1Row[K,V],Tensor1Col[K,V]] {\n    override def apply(from : Tensor1Row[K,V]) =\n      from.t;\n  }\n\n  implicit def canTransposeTensor1Col[K,V]\n  : CanTranspose[Tensor1Col[K,V],Tensor1Row[K,V]]\n  = new CanTranspose[Tensor1Col[K,V],Tensor1Row[K,V]] {\n    override def apply(from : Tensor1Col[K,V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeTensor2[K2,K1,V]\n  : CanTranspose[Tensor2[K1,K2,V],Tensor2[K2,K1,V]]\n  = new CanTranspose[Tensor2[K1,K2,V],Tensor2[K2,K1,V]] {\n    override def apply(from : Tensor2[K1,K2,V]) = {\n      from.t;\n    }\n  }\n}\n\ntrait CanTransposeImplicitsLevel0M extends CanTransposeImplicitsLevel0 {\n  implicit def canTransposeMutableTensor1Col[K,V]\n  : CanTranspose[mutable.Tensor1Col[K,V],mutable.Tensor1Row[K,V]]\n  = new CanTranspose[mutable.Tensor1Col[K,V],mutable.Tensor1Row[K,V]] {\n    override def apply(from : mutable.Tensor1Col[K,V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeMutableTensor1Row[K,V]\n  : CanTranspose[mutable.Tensor1Row[K,V],mutable.Tensor1Col[K,V]]\n  = new CanTranspose[mutable.Tensor1Row[K,V],mutable.Tensor1Col[K,V]] {\n    override def apply(from : mutable.Tensor1Row[K,V]) =\n      from.t;\n  }\n}\n\ntrait CanTransposeImplicitsLevel1 extends CanTransposeImplicitsLevel0M {\n  implicit def canTransposeVectorRow[V] : CanTranspose[VectorRow[V],VectorCol[V]]\n  = new CanTranspose[VectorRow[V],VectorCol[V]] {\n    override def apply(from : VectorRow[V]) =\n      from.t;\n  }\n\n  implicit def canTransposeVectorCol[V] : CanTranspose[VectorCol[V],VectorRow[V]]\n  = new CanTranspose[VectorCol[V],VectorRow[V]] {\n    override def apply(from : VectorCol[V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeMatrix[V] : CanTranspose[Matrix[V],Matrix[V]] =\n  new CanTranspose[Matrix[V],Matrix[V]] {\n    override def apply(from : Matrix[V]) =\n      from.t;\n  }\n}\n\ntrait CanTransposeImplicitsLevel1M extends CanTransposeImplicitsLevel1 {\n  implicit def canTransposeMutableVectorCol[V]\n  : CanTranspose[mutable.VectorCol[V],mutable.VectorRow[V]]\n  = new CanTranspose[mutable.VectorCol[V],mutable.VectorRow[V]] {\n    override def apply(from : mutable.VectorCol[V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeMutableVectorRow[V]\n  : CanTranspose[mutable.VectorRow[V],mutable.VectorCol[V]]\n  = new CanTranspose[mutable.VectorRow[V],mutable.VectorCol[V]] {\n    override def apply(from : mutable.VectorRow[V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeMutableMatrix[V] : CanTranspose[mutable.Matrix[V],mutable.Matrix[V]] =\n  new CanTranspose[mutable.Matrix[V],mutable.Matrix[V]] {\n    override def apply(from : mutable.Matrix[V]) =\n      from.t;\n  }\n}\n\ntrait CanTransposeImplicitsLevel2 {\n  implicit def canTransposeSparseVectorRow[V] : CanTranspose[sparse.SparseVectorRow[V],sparse.SparseVectorCol[V]]\n  = new CanTranspose[sparse.SparseVectorRow[V],sparse.SparseVectorCol[V]] {\n    override def apply(from : sparse.SparseVectorRow[V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeSparseVectorCol[V] : CanTranspose[sparse.SparseVectorCol[V],sparse.SparseVectorRow[V]]\n  = new CanTranspose[sparse.SparseVectorCol[V],sparse.SparseVectorRow[V]] {\n    override def apply(from : sparse.SparseVectorCol[V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeDenseVectorRow[V] : CanTranspose[dense.DenseVectorRow[V],dense.DenseVectorCol[V]]\n  = new CanTranspose[dense.DenseVectorRow[V],dense.DenseVectorCol[V]] {\n    override def apply(from : dense.DenseVectorRow[V]) =\n      from.t;\n  }\n  \n  implicit def canTransposeDenseVectorCol[V] : CanTranspose[dense.DenseVectorCol[V],dense.DenseVectorRow[V]]\n  = new CanTranspose[dense.DenseVectorCol[V],dense.DenseVectorRow[V]] {\n    override def apply(from : dense.DenseVectorCol[V]) =\n      from.t;\n  }\n}\n\nobject CanTranspose extends CanTransposeImplicitsLevel2 {\n  \n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanView.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\n/**\n * Trait for constructing a lazy view of a given Tensor.\n *\n * @author dramage\n */\ntrait CanView[-From, +To] {\n  def apply(from : From) : To;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanViewAsTensor1.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.collection.sparse.SparseArray;\n\nimport scalala.scalar.Scalar;\nimport scalala.tensor.Tensor1;\nimport scalala.tensor.dense.DenseVectorCol;\nimport scalala.tensor.sparse.SparseVectorCol;\n\n/**\n * View something as a Tensor1.\n *\n * @author dramage\n */\ntrait CanViewAsTensor1[-From,K,V] {\n  def apply(from : From) : Tensor1[K,V];\n}\n\nobject CanViewAsTensor1 {\n  //\n  // View arrays\n  //\n\n  class ArrayTensor1[V:ClassManifest:Scalar]\n  extends CanViewAsTensor1[Array[V],Int,V] {\n    def apply(from : Array[V]) = new DenseVectorCol[V](from);\n  }\n\n  implicit def mkArrayTensor1[V:ClassManifest:Scalar] =\n    new ArrayTensor1[V]();\n\n  implicit object ArrayI extends ArrayTensor1[Int];\n  implicit object ArrayS extends ArrayTensor1[Short];\n  implicit object ArrayL extends ArrayTensor1[Long];\n  implicit object ArrayF extends ArrayTensor1[Float];\n  implicit object ArrayD extends ArrayTensor1[Double];\n  implicit object ArrayB extends ArrayTensor1[Boolean];\n\n  //\n  // View sparse arrays\n  //\n\n  class SparseArrayTensor1[V:ClassManifest:Scalar]\n  extends CanViewAsTensor1[SparseArray[V],Int,V] {\n    def apply(from : SparseArray[V]) = new SparseVectorCol[V](from);\n  }\n\n  implicit def mkSparseArrayTensor1[V:ClassManifest:Scalar] =\n    new SparseArrayTensor1[V]();\n\n  implicit object SparseArrayI extends SparseArrayTensor1[Int];\n  implicit object SparseArrayS extends SparseArrayTensor1[Short];\n  implicit object SparseArrayL extends SparseArrayTensor1[Long];\n  implicit object SparseArrayF extends SparseArrayTensor1[Float];\n  implicit object SparseArrayD extends SparseArrayTensor1[Double];\n  implicit object SparseArrayB extends SparseArrayTensor1[Boolean];\n\n  //\n  // View pre-constructed Tensor1 instances\n  //\n\n  class Tensor1Tensor1[K,V:Scalar]\n  extends CanViewAsTensor1[Tensor1[K,V],K,V] {\n    def apply(from : Tensor1[K,V]) = from;\n  }\n\n  implicit def mkTensor1Tensor1[K,V:Scalar] =\n    new Tensor1Tensor1[K,V]();\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanViewAsTensor2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.scalar.Scalar;\nimport scalala.tensor.Tensor2;\nimport scalala.tensor.dense.ArrayArrayMatrix;\n\n/**\n * View something as a Tensor1.\n *\n * @author dramage\n */\ntrait CanViewAsTensor2[-From,K1,K2,V] {\n  def apply(from : From) : Tensor2[K1,K2,V];\n}\n\nobject CanViewAsTensor2 {\n  //\n  // View arrays\n  //\n\n  class ArrayArrayTensor2[V:ClassManifest:Scalar]\n  extends CanViewAsTensor2[Array[Array[V]],Int,Int,V] {\n    def apply(from : Array[Array[V]]) = new ArrayArrayMatrix[V](from);\n  }\n\n  implicit def mkArrayArrayTensor2[V:ClassManifest:Scalar] =\n    new ArrayArrayTensor2[V]();\n\n  implicit object ArrayArrayI extends ArrayArrayTensor2[Int];\n  implicit object ArrayArrayS extends ArrayArrayTensor2[Short];\n  implicit object ArrayArrayL extends ArrayArrayTensor2[Long];\n  implicit object ArrayArrayF extends ArrayArrayTensor2[Float];\n  implicit object ArrayArrayD extends ArrayArrayTensor2[Double];\n  implicit object ArrayArrayB extends ArrayArrayTensor2[Boolean];\n\n  //\n  // View pre-constructed Tensor2 instances\n  //\n\n  class Tensor2Tensor2[K1,K2,V:Scalar]\n  extends CanViewAsTensor2[Tensor2[K1,K2,V],K1,K2,V] {\n    def apply(from : Tensor2[K1,K2,V]) = from;\n  }\n\n  implicit def mkTensor2Tensor2[K1,K2,V:Scalar] =\n    new Tensor2Tensor2[K1,K2,V]();\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanViewAsVector.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport scalala.collection.sparse.SparseArray;\n\nimport scalala.scalar.Scalar;\nimport scalala.tensor.Vector;\nimport scalala.tensor.dense.DenseVectorCol;\nimport scalala.tensor.sparse.SparseVectorCol;\n\n/**\n * View something as a Vector.\n *\n * @author dramage\n */\ntrait CanViewAsVector[-From,V] {\n  def apply(from : From) : Vector[V];\n}\n\nobject CanViewAsVector {\n  //\n  // View arrays\n  //\n\n  class ArrayVector[V:ClassManifest:Scalar]\n  extends CanViewAsVector[Array[V],V] {\n    def apply(from : Array[V]) = new DenseVectorCol[V](from);\n  }\n\n  implicit def mkArrayVector[V:ClassManifest:Scalar] =\n    new ArrayVector[V]();\n\n  implicit object ArrayI extends ArrayVector[Int];\n  implicit object ArrayS extends ArrayVector[Short];\n  implicit object ArrayL extends ArrayVector[Long];\n  implicit object ArrayF extends ArrayVector[Float];\n  implicit object ArrayD extends ArrayVector[Double];\n  implicit object ArrayB extends ArrayVector[Boolean];\n\n  //\n  // View sparse arrays\n  //\n\n  class SparseArrayVector[V:ClassManifest:Scalar]\n  extends CanViewAsVector[SparseArray[V],V] {\n    def apply(from : SparseArray[V]) = new SparseVectorCol[V](from);\n  }\n\n  implicit def mkSparseArrayVector[V:ClassManifest:Scalar] =\n    new SparseArrayVector[V]();\n\n  implicit object SparseArrayI extends SparseArrayVector[Int];\n  implicit object SparseArrayS extends SparseArrayVector[Short];\n  implicit object SparseArrayL extends SparseArrayVector[Long];\n  implicit object SparseArrayF extends SparseArrayVector[Float];\n  implicit object SparseArrayD extends SparseArrayVector[Double];\n  implicit object SparseArrayB extends SparseArrayVector[Boolean];\n\n  //\n  // View pre-constructed Vector instances\n  //\n\n  class VectorVector[V:Scalar]\n  extends CanViewAsVector[Vector[V],V] {\n    def apply(from : Vector[V]) = from;\n  }\n\n  implicit def mkVectorVector[V:Scalar] =\n    new VectorVector[V]();\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanZipMapValues.scala",
    "content": "package scalala\npackage generic\npackage collection\n\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\nimport scalala.scalar.Complex\nimport scalala.collection.sparse.{SparseArray, DefaultArrayValue}\nimport tensor.domain.CanGetDomain\n;\n\n/**\n * Marker for being able to zip two From's and map the values to a new collection\n *\n * @author dlwh\n */\ntrait CanZipMapValues[From, @specialized A, @specialized B, +To] {\n  /** Maps all corresponding values from the two collection. */\n  def map(from : From, from2: From, fn : (A,A)=>B) : To;\n}\n\nobject CanZipMapValues {\n  type Op[From, A, B, To] = CanZipMapValues[From, A, B, To];\n\n  //\n  // Arrays\n  //\n\n  class OpArray[@specialized A, @specialized B: ClassManifest]\n    extends Op[Array[A], A, B, Array[B]] {\n\n    /**Maps all values from the given collection. */\n    def map(from: Array[A], from2: Array[A], fn: (A, A) => B) = {\n      require(from.length == from2.length, \"Array lengths don't match!\")\n      val arr = new Array[B](from.length)\n      for(i <- 0 until from.length) {\n        arr(i) = fn(from(i), from2(i))\n      }\n      arr\n    }\n\n  }\n\n\n  implicit def opArray[@specialized A, @specialized B: ClassManifest] =\n    new OpArray[A, B];\n\n  implicit object OpArrayII extends OpArray[Int, Int];\n\n  implicit object OpArraySS extends OpArray[Short, Short];\n\n  implicit object OpArrayLL extends OpArray[Long, Long];\n\n  implicit object OpArrayFF extends OpArray[Float, Float];\n\n  implicit object OpArrayDD extends OpArray[Double, Double];\n\n  implicit object OpArrayCC extends OpArray[Complex, Complex];\n\n  implicit object OpArrayID extends OpArray[Int, Double];\n\n  implicit object OpArraySD extends OpArray[Short, Double];\n\n  implicit object OpArrayLD extends OpArray[Long, Double];\n\n  implicit object OpArrayFD extends OpArray[Float, Double];\n\n  implicit def canZipMapFromJoin[From,K,V,Domain,V2,To](implicit canJoin: CanJoin[From, From, K, V, V],\n                                                        dom: CanGetDomain[From, Domain],\n                                                        cbf: CanBuildTensorFrom[From, Domain, K, V2, To]):CanZipMapValues[From, V, V2, To] = {\n    new CanZipMapValues[From, V, V2, To] {\n      /**Maps all corresponding values from the two collection. */\n      def map(from: From, from2: From, fn: (V, V) => V2) = {\n        val b = cbf(from, dom(from))\n        canJoin.joinAll(from, from2, {(k,v,v2) => b.update(k, fn(v,v2))})\n        b.result\n      }\n    }\n  }\n\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanAbs.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport scalala.operators.UnaryOp\nimport collection.CanMapValues\n\n\n/**\n * Operator type for abs(A).\n *\n * @author dramage\n */\ntrait OpAbs extends operators.OpType;\nobject OpAbs extends OpAbs;\n\n\n/**\n * Construction delegate for abs(A).\n * \n * @author dlwh\n */\ntrait CanAbs[-A,+RV] extends UnaryOp[A,OpAbs,RV] {\n  def opType = OpAbs;\n  def apply(v: A):RV;\n}\n\nobject CanAbs {\n  implicit object OpI extends CanAbs[Int,Double] {\n    def apply(v : Int) = scala.math.abs(v);\n  }\n\n  implicit object OpL extends CanAbs[Long,Double] {\n    def apply(v : Long) = scala.math.abs(v);\n  }\n\n  implicit object OpF extends CanAbs[Float,Double] {\n    def apply(v : Float) = scala.math.abs(v);\n  }\n\n  implicit object OpD extends CanAbs[Double,Double] {\n    def apply(v : Double) = scala.math.abs(v);\n  }\n\n  class OpMapValues[From,A,B,To](implicit op : CanAbs[A,B], map : CanMapValues[From,A,B,To]) extends CanAbs[From,To] {\n    def apply(v : From) = map.map(v, op.apply(_));\n  }\n\n  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanAbs[A,B])\n  : CanAbs[From,To] = new OpMapValues[From,A,B,To]()(op, map);\n\n  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);\n  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);\n  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);\n  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);\n}"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanExp.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport collection.CanMapValues;\n\nimport scalala.operators.{UnaryOp}\nimport scalala.scalar.Complex\nimport scalala.tensor.{Matrix, Vector}\n\n/**\n * Operator type for exp(A).\n *\n * @author dramage\n */\ntrait OpExp extends operators.OpType;\nobject OpExp extends OpExp;\n\n/**\n * Constructiond delegate for exp(A).\n *\n * @author dramage\n */\ntrait CanExp[A,+RV] extends UnaryOp[A,OpExp,RV] {\n  def opType = OpExp;\n}\n\nobject CanExp {\n  implicit object OpI extends CanExp[Int,Double] {\n    def apply(v : Int) = scala.math.exp(v);\n  }\n\n  implicit object OpL extends CanExp[Long,Double] {\n    def apply(v : Long) = scala.math.exp(v);\n  }\n\n  implicit object OpF extends CanExp[Float,Double] {\n    def apply(v : Float) = scala.math.exp(v);\n  }\n\n  implicit object OpD extends CanExp[Double,Double] {\n    def apply(v : Double) = scala.math.exp(v);\n  }\n\n  implicit object OpC extends CanExp[Complex,Complex] {\n    def apply(v: Complex) = Complex(scala.math.cos(v.imag), scala.math.sin(v.imag)) * scala.math.exp(v.real)\n  }\n\n  class OpMapValues[From,A,B,To](implicit op : CanExp[A,B], map : CanMapValues[From,A,B,To]) extends CanExp[From,To] {\n    def apply(v : From) = map.map(v, op.apply(_));\n  }\n\n  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanExp[A,B])\n  : CanExp[From,To] = new OpMapValues[From,A,B,To]()(op, map);\n\n  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);\n  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);\n  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);\n  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);\n  implicit object OpArrayC extends OpMapValues[Array[Complex],Complex,Complex,Array[Complex]]()(OpC,CanMapValues.OpArrayCC);\n\n  implicit object OpVectorI extends OpMapValues[Vector[Int],Int,Double,Vector[Double]]()\n  implicit object OpVectorL extends OpMapValues[Vector[Long],Long,Double,Vector[Double]]()\n  implicit object OpVectorF extends OpMapValues[Vector[Float],Float,Double,Vector[Double]]()\n  implicit object OpVectorD extends OpMapValues[Vector[Double],Double,Double,Vector[Double]]()\n\n  implicit object OpMatrixI extends OpMapValues[Matrix[Int],Int,Double,Matrix[Double]]()\n  implicit object OpMatrixL extends OpMapValues[Matrix[Long],Long,Double,Matrix[Double]]()\n  implicit object OpMatrixF extends OpMapValues[Matrix[Float],Float,Double,Matrix[Double]]()\n  implicit object OpMatrixD extends OpMapValues[Matrix[Double],Double,Double,Matrix[Double]]()\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanLog.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport collection.CanMapValues;\nimport scalala.operators.UnaryOp\nimport tensor.{Matrix, Vector}\n;\n\n/**\n * Operator type for log(A).\n *\n * @author dramage\n */\ntrait OpLog extends operators.OpType;\nobject OpLog extends OpLog;\n\n/**\n * Constructiond delegate for log(A).\n * \n * @author dramage\n */\ntrait CanLog[-A,+RV] extends UnaryOp[A,OpLog,RV] {\n  def opType = OpLog;\n}\n\nobject CanLog {\n  implicit object OpI extends CanLog[Int,Double] {\n    def apply(v : Int) = scala.math.log(v);\n  }\n\n  implicit object OpL extends CanLog[Long,Double] {\n    def apply(v : Long) = scala.math.log(v);\n  }\n\n  implicit object OpF extends CanLog[Float,Double] {\n    def apply(v : Float) = scala.math.log(v);\n  }\n\n  implicit object OpD extends CanLog[Double,Double] {\n    def apply(v : Double) = scala.math.log(v);\n  }\n  \n  class OpMapValues[From,A,B,To](implicit op : CanLog[A,B], map : CanMapValues[From,A,B,To]) extends CanLog[From,To] {\n    def apply(v : From) = map.map(v, op.apply(_));\n  }\n\n  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanLog[A,B])\n  : CanLog[From,To] = new OpMapValues[From,A,B,To]()(op, map);\n\n  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);\n  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);\n  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);\n  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);\n\n  implicit object OpVectorI extends OpMapValues[Vector[Int],Int,Double,Vector[Double]]()\n  implicit object OpVectorL extends OpMapValues[Vector[Long],Long,Double,Vector[Double]]()\n  implicit object OpVectorF extends OpMapValues[Vector[Float],Float,Double,Vector[Double]]()\n  implicit object OpVectorD extends OpMapValues[Vector[Double],Double,Double,Vector[Double]]()\n\n  implicit object OpMatrixI extends OpMapValues[Matrix[Int],Int,Double,Matrix[Double]]()\n  implicit object OpMatrixL extends OpMapValues[Matrix[Long],Long,Double,Matrix[Double]]()\n  implicit object OpMatrixF extends OpMapValues[Matrix[Float],Float,Double,Matrix[Double]]()\n  implicit object OpMatrixD extends OpMapValues[Matrix[Double],Double,Double,Matrix[Double]]()\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanMean.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport scalala.generic.collection.CanCreateZerosLike;\nimport scalala.operators._;\nimport scalala.tensor.Tensor;\nimport scalala.scalar.ScalarDecimal;\n\n/**\n * Construction delegate for mean(From).\n * \n * @author dramage\n */\ntrait CanMean[-From,+To] extends (From=>To);\n\ntrait LowPriorityCanMean {\n  /** Computes the mean by adding and dividing.  This is slower than the implementation in ZeroInto. */\n  implicit def AddDiv[V](implicit add : BinaryOp[V,V,OpAdd,V], div : BinaryOp[V,Int,OpDiv,V])\n  : CanMean[Traversable[V],V] = new CanMean[Traversable[V],V] {\n    def apply(values : Traversable[V]) = {\n      var current = values.head;\n      var n = 0;\n      for (value <- values) {\n        if (n >= 1) {\n          current = add(current, value);\n        }\n        n += 1;\n      }\n      div(current, n);\n    }\n  }\n}\n\nobject CanMean { // extends LowPriorityCanMean {\n  /** Numerically stable one-pass mean computation. */\n  implicit def TraversableOnceMeanScalar[S](implicit view : S=>Double)\n  : CanMean[TraversableOnce[S],Double]\n  = new CanMean[TraversableOnce[S],Double] {\n    def apply(values : TraversableOnce[S]) = {\n      var m = 0.0;\n      var k = 0;\n      for (x <- values) {\n        k += 1;\n        m += (x - m) / k;\n      }\n      m;\n    }\n  }\n  \n  /** Optimized implementation for array of doubles. */\n  implicit def ArrayMeanScalar[S](implicit view : S=>Double)\n  : CanMean[Array[S],Double]\n  = new CanMean[Array[S],Double] {\n    def apply(values : Array[S]) = {\n      var m = 0.0;\n      var k = 0;\n      while (k < values.length) {\n        m += (values(k) - m) / (k + 1);\n        k += 1;\n      }\n      m;\n    }\n  }\n\n  /** Numerically stable generic one-pass mean computation. */\n  implicit def TensorMean[T,V,D](implicit tv : T=>Tensor[_,V],\n    sd : ScalarDecimal[V,D],\n    add : BinaryOp[D,D,OpAdd,D],\n    sub : BinaryOp[V,D,OpSub,D],\n    div : BinaryOp[D,Int,OpDiv,D],\n    mul : BinaryOp[D,Double,OpMul,D])\n  : CanMean[T,D] = new CanMean[T,D] {\n    def apply(tensor : T) = {\n      var m = sd.decimal.zero;\n      var k = 0;\n      tensor.foreachNonZeroValue(x => {\n        k += 1;\n        m = add(m,div(sub(x,m),k));\n      });\n      mul(m,  k.toDouble / tensor.size);\n    }\n  }\n\n  /** Computes the mean by starting with zero, adding into it, and dividing into it. */\n  implicit def ZeroInto[V,RV](implicit zero : CanCreateZerosLike[V,RV],\n   addInto : BinaryUpdateOp[RV,V,OpAdd], divInto : BinaryUpdateOp[RV,Int,OpDiv])\n  : CanMean[TraversableOnce[V],RV] = new CanMean[TraversableOnce[V],RV] {\n    def apply(values : TraversableOnce[V]) : RV = {\n      var sum : RV = null.asInstanceOf[RV];\n      var k = 0;\n      for (value <- values) {\n        if (k == 0) {\n          sum = zero(value);\n        }\n        addInto(sum, value);\n        k += 1;\n      }\n      divInto(sum, k);\n      sum;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanNorm.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport collection.CanViewAsTensor1;\n\n/**\n * Construction delegate for getting the norm of a value of type From.\n *\n * @author dramage\n */\ntrait CanNorm[-From] extends ((From,Double)=>Double);\n\nobject CanNorm {\n  implicit def mkTensor1Norm[T](implicit tt : CanViewAsTensor1[T,_,_])\n  : CanNorm[T] = new CanNorm[T] {\n    def apply(t : T, n : Double) : Double =\n      tt(t).norm(n);\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanSoftmax.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport collection.CanViewAsTensor1;\n\n/**\n * Construction delegate for getting the softmax of a type.\n *\n * @author dlwh\n */\ntrait CanSoftmax[-From] {\n  // shouldn't be apply, because function1's are bad implicits\n  def softmax(x: From):Double\n}\n\nobject CanSoftmax {\n  implicit def mkTensor1Softmax[K,T](implicit tt : CanViewAsTensor1[T,K,Double])\n  : CanSoftmax[T] = new CanSoftmax[T] {\n    def softmax(t : T) : Double = {\n      val value = tt(t);\n      val max = value.max;\n      val part = value.valuesIterator.foldLeft(0.0)((acc,v) => acc + scala.math.exp(v - max));\n      max + scala.math.log(part);\n    }\n  }\n\n\n}\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanSqrt.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport collection.CanMapValues;\n\nimport scalala.operators.{UnaryOp,OpType};\n\ntrait OpSqrt extends OpType;\nobject OpSqrt extends OpSqrt;\n\n/**\n * Constructiond delegate for sqrt(A).\n *\n * @author dramage\n */\ntrait CanSqrt[-A,+RV] extends UnaryOp[A,OpSqrt,RV] {\n  def opType = OpSqrt;\n}\n\nobject CanSqrt {\n  implicit object OpI extends CanSqrt[Int,Double] {\n    def apply(v : Int) = scala.math.sqrt(v);\n  }\n\n  implicit object OpL extends CanSqrt[Long,Double] {\n    def apply(v : Long) = scala.math.sqrt(v);\n  }\n\n  implicit object OpF extends CanSqrt[Float,Double] {\n    def apply(v : Float) = scala.math.sqrt(v);\n  }\n\n  implicit object OpD extends CanSqrt[Double,Double] {\n    def apply(v : Double) = scala.math.sqrt(v);\n  }\n\n  class OpMapValues[From,A,B,To](implicit op : CanSqrt[A,B], map : CanMapValues[From,A,B,To]) extends CanSqrt[From,To] {\n    def apply(v : From) = map.map(v, op.apply(_));\n  }\n\n  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanSqrt[A,B])\n  : CanSqrt[From,To] = new OpMapValues[From,A,B,To]()(op, map);\n\n  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);\n  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);\n  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);\n  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanVariance.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage generic;\npackage math;\n\nimport scalala.generic.collection.CanCreateZerosLike;\nimport scalala.operators._;\nimport scalala.tensor.Tensor;\nimport scalala.scalar.ScalarDecimal;\n\n/**\n * Construction delegate for variance(From).\n * \n * @author dramage\n */\ntrait CanVariance[-From,+To] extends (From=>To);\n\nobject CanVariance {\n  /**\n   * Numerically stable one-pass sample variance computation.\n   *\n   * From http://www.cs.berkeley.edu/~mhoemmen/cs194/Tutorials/variance.pdf\n   */\n  implicit def TraversableOnceVarianceScalar[S](implicit view : S=>Double)\n  : CanVariance[TraversableOnce[S],Double]\n  = new CanVariance[TraversableOnce[S],Double] {\n    def apply(values : TraversableOnce[S]) = {\n      var m = 0.0;\n      var q = 0.0;\n      var k = 0;\n      for (x <- values) {\n        k += 1;\n        val xMm = x - m;\n        val xMmDk = xMm / k;\n        m = m + xMmDk;\n        q = q + (k - 1) * xMm * xMmDk\n      }\n      q / (k - 1);\n    }\n  }\n  \n  implicit def ArrayVarianceScalar[S](implicit view : S=>Double)\n  : CanVariance[Array[S],Double]\n  = new CanVariance[Array[S],Double] {\n    def apply(values : Array[S]) = {\n      var m = 0.0;\n      var q = 0.0;\n      var k = 0;\n      while (k < values.length) {\n        val x = values(k);\n        k += 1;\n        val xMm = x - m;\n        val xMmDk = xMm / k;\n        m = m + xMmDk;\n        q = q + (k - 1) * xMm * xMmDk\n      }\n      q / (k - 1);\n    }\n  }\n  \n  implicit def TensorVariance[T,V,D](implicit view : T=>Tensor[_,V],\n    sd : ScalarDecimal[V,D],\n    sub  : BinaryOp[V,D,OpSub,D],\n    add  : BinaryOp[D,D,OpAdd,D],\n    div  : BinaryOp[D,Int,OpDiv,D],\n    mul1 : BinaryOp[D,D,OpMul,D],\n    mul2 : BinaryOp[D,Int,OpMul,D])\n  : CanVariance[T,D]\n  = new CanVariance[T,D] {\n    override def apply(tensor : T) = {\n      var m = sd.decimal.zero;\n      var q = sd.decimal.zero;\n      var k = 0;\n      // TODO: this could be more efficient by using foreachNonZeroValue\n      tensor.foreachValue(x => {\n        k += 1;\n        val xMm = sub(x, m);\n        val xMmDk = div(xMm, k);\n        m = add(m, xMmDk);\n        q = add(q, mul2(mul1(xMm,xMmDk), k-1));\n      });\n      div(q, k-1);\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/Library.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\n\nimport scalala.generic.math._\nimport scalala.tensor.mutable.Counter;\nimport tensor._\nimport dense._\nimport domain.CanGetDomain\nimport scalar.Scalar\nimport operators._\nimport scalala.generic.collection._\n\n/**\n * Library of scalala basic mathematical functions.\n *\n * @author dramage, afwlehmann\n */\ntrait Library {\n\n  //\n  // Aliases to scala math package.\n  //\n\n  /** Alias for math.log. */\n  final def log(v : Double) : Double = scala.math.log(v);\n\n  /** Alias for math.log1p. */\n  final def log1p(v : Double) : Double = scala.math.log1p(v);\n\n  /** Alias for math.exp. */\n  final def exp(v : Double) : Double = scala.math.exp(v);\n\n  /** Alias for math.pow. */\n  final def pow(base : Double, exponent : Double) : Double =\n    scala.math.pow(base, exponent);\n\n  /** Alias for math.abs. */\n  final def abs(v : Double) : Double = scala.math.abs(v);\n\n  /** Alias for x.isNaN. */\n  final def isnan(x : Double) = java.lang.Double.isNaN(x);\n\n  /** Alias for math.sqrt. */\n  final def sqrt(x : Double) = scala.math.sqrt(x);\n\n  /** Alias for Double.NaN */\n  final val NaN = Double.NaN;\n\n  /** Alias for Double.NaN */\n  final val nan = NaN;\n\n  /** Alias for Double.PositiveInfinity */\n  final val Inf = Double.PositiveInfinity;\n\n  /** Alias for Double.PositiveInfinity */\n  final val inf = Inf;\n\n  //\n  // Collection level operations\n  //\n\n  /** Take the log of the given value. */\n  def log[V,That](value : V)(implicit log : CanLog[V,That]) : That =\n    log(value);\n\n  /** Take the exp of the given value. */\n  def exp[V,That](value : V)(implicit exp : CanExp[V,That]) : That =\n    exp(value);\n\n    /** Take the log of the given value. */\n  def abs[V,That](value : V)(implicit abs : CanAbs[V,That]) : That =\n    abs(value);\n\n  /** Take the n-norm of the given values. */\n  def mean[V,That](value : V)(implicit mean : CanMean[V,That]) : That =\n    mean(value);\n\n  /** Take the n-norm of the given value. */\n  def norm[V](value : V, n : Double)(implicit norm : CanNorm[V]) : Double =\n    norm(value, n);\n\n  /** Take the sqrt of the given value. */\n  def sqrt[V,That](value : V)(implicit sqrt : CanSqrt[V,That]) : That =\n    sqrt(value);\n\n  /** Take the standard deviation of a collection. */\n  def stddev[V,VV,That](data : V)\n  (implicit variance : CanVariance[V,VV], sqrt : CanSqrt[VV,That]) : That =\n    sqrt(variance(data));\n\n  /** Take the variance of a collection. */\n  def variance[V,That](data : V)(implicit variance : CanVariance[V,That]) =\n    variance(data);\n\n  /** Take the softmax of a collection. */\n  def softmax[V](value: V)(implicit softmax: CanSoftmax[V]) : Double =\n    softmax.softmax(value)\n\n  sealed trait Axis;\n  object Axis {\n    type Value = Axis\n    case object Horizontal extends Axis;\n    case object Vertical extends Axis;\n  }\n\n  /**\n   * Minimum vector of the given matrix along the specified axis.\n   */\n  def min[T: Scalar](X: Matrix[T], axis: Axis.Value): DenseVector[T] = {\n    axis match {\n      case Axis.Horizontal => DenseVectorCol.tabulate[T](X.numRows)(X(_,::).min)\n      case Axis.Vertical => DenseVectorRow.tabulate[T](X.numCols)(X(::,_).min)\n    }\n  }\n\n  /**\n   * Maximum vector of the given matrix along the specified axis.\n   */\n  def max[T: Scalar](X: Matrix[T], axis: Axis.Value): DenseVector[T] = {\n    axis match {\n      case Axis.Horizontal => DenseVectorCol.tabulate[T](X.numRows)(X(_,::).max)\n      case Axis.Vertical => DenseVectorRow.tabulate[T](X.numCols)(X(::,_).max)\n    }\n  }\n\n  /**\n   * Mean vector of the given matrix along the specified axis.\n   */\n  def mean[@specialized T](X: Matrix[T], axis: Axis.Value)(implicit xv: T => Double)\n  : DenseVector[Double] = {\n    // TODO: This calculation of the mean is rather slow. It should\n    //       be transformed into several while loops.\n    axis match {\n      case Axis.Horizontal =>\n        var mu = DenseVector.zeros[Double](X.numRows)\n        X foreachTriple ( (i, j, value) =>\n          mu(i) += (value - mu(i)) / (j + 1)\n        )\n        mu\n\n      case Axis.Vertical =>\n        var mu = DenseVector.zeros[Double](X.numCols)\n        X foreachTriple ( (i, j, value) =>\n          mu(j) += (value - mu(j)) / (i + 1)\n        )\n        mu.t\n    }\n  }\n\n  /**\n   * Creates a copy of the object using the CanCopy implicit.\n   */\n  def copy[T](t: T)(implicit canCopy: CanCopy[T]) = canCopy(t)\n\n  /**\n   * The covariance matrix and mean of the given dataset X where the samples of\n   * a multivariate random distribution are stacked along the given axis.\n   */\n  def covariance(X: Matrix[Double], axis: Axis.Value = Axis.Horizontal):\n    (DenseMatrix[Double], DenseVector[Double]) =\n  {\n    require(X.numCols > 0 && X.numRows > 0)\n\n    axis match {\n      case Axis.Horizontal =>\n        val dim   = X.numRows\n        val mu    = DenseVector.tabulate[Double](dim)(X(_,0))\n        val Sigma = DenseMatrix.zeros[Double](dim, dim)\n        var K     = 1.0\n        for (i <- 1 until X.numCols) {\n          val xMinusMu = X(::,i) - mu\n          K     += 1\n          mu    += xMinusMu / K\n          Sigma += xMinusMu * xMinusMu.t * (1d - 1d / K)\n        }\n        (Sigma / math.max(1, K-1), mu)\n\n      case Axis.Vertical =>\n        val dim   = X.numCols\n        val mu    = DenseVector.tabulate[Double](dim)(X(0,_))\n        val Sigma = DenseMatrix.zeros[Double](dim, dim)\n        var K     = 1.0\n        for (i <- 1 until X.numRows) {\n          val xMinusMu = X(i,::) - mu\n          K     += 1\n          mu    += xMinusMu / K\n          Sigma += xMinusMu.t * xMinusMu * (1d - 1d / K)\n        }\n        (Sigma / math.max(1, K-1), mu)\n    }\n  }\n\n  /** Sums the tensor2 along the horizontal axis */\n  def sum[K1,K2,V,T,ADomain,Row](matrix: T,\n                                 axis: Axis.Horizontal.type = Axis.Horizontal)\n                                (implicit view: T=>Tensor2[K1,K2,V],\n                                 sliceRows: CanSliceRow[T,K1,Row],\n                                 opAdd: BinaryOp[Row,Row,OpAdd,Row]):Row  = {\n    matrix.domain._1.view.map(sliceRows(matrix,_)).reduceLeft(opAdd);\n  }\n\n\n  /** Sums the tensor2 along the vertical axis */\n  def sum[K1,K2,V,T,ADomain,Col](matrix: T,\n                                 axis: Axis.Vertical.type)\n                                (implicit view: T=>Tensor2[K1,K2,V],\n                                 sliceCols: CanSliceCol[T,K2,Col],\n                                 opAdd: BinaryOp[Col,Col,OpAdd,Col]):Col  = {\n    matrix.domain._2.view.map(sliceCols(matrix,_)).reduceLeft(opAdd);\n  }\n\n  //\n  // Constructors\n  //\n\n  /** Counts the given items. */\n  def count[X](items : TraversableOnce[X]) : Counter[X,Int] =\n    Counter.count(items);\n\n  //\n  // normalization and log-normalization:\n  //\n\n  /**\n   * Normalizes the argument such that its norm is 1.0 (with respect to the argument n).\n   * Returns value if value's norm is 0.\n   */\n  def normalize[V,K,That](value: V, n: Double)(implicit _norm: CanNorm[V], st: V<:<NumericOps[V], op: BinaryOp[V,Double,OpDiv,V]):V = {\n    val norm = _norm(value,n)\n    if(norm == 0) value\n    else value / norm;\n  }\n\n  /**\n   * logNormalizes the argument such that the softmax is 0.0.\n   * Returns value if value's softmax is -infinity\n   */\n  def logNormalize[V,K](value: V)(implicit view: V => NumericOps[V],\n                                  sm: CanSoftmax[V],\n                                  op : BinaryOp[V,Double,OpSub,V]): V = {\n    val max = softmax(value)\n    if(max.isInfinite) value\n    else value - max;\n  }\n\n  /**\n   * logs and then logNormalizes the argument such that the softmax is 0.0.\n   * Returns value if value's softmax is -infinity\n   */\n  def logAndNormalize[V](value: V)(implicit canLog : CanLog[V,V],\n                                     view: V => NumericOps[V], sm: CanSoftmax[V],\n                                     op : BinaryOp[V,Double,OpSub,V]):V = {\n    logNormalize(log(value))\n  }\n\n  def logAndNormalizeRows[T,K1,K2,Row,ADomain,That](matrix: T)(implicit view: T=>Tensor2[K1,K2,Double],\n                                                    domainA : CanGetDomain[T,ADomain],\n                                                    sliceRows: CanSliceRow[T,K1,Row],\n                                                    canLog: CanMapValues[Row,Double,Double,Row],\n                                                    view2: Row => Tensor1[K2,Double] with NumericOps[Row], sm: CanSoftmax[Row],\n                                                    op : BinaryOp[Row,Double,OpSub,Row],\n                                                    bf : CanBuildTensorFrom[T,ADomain,(K1,K2),Double,That]): That = {\n    val builder = bf(matrix,domainA(matrix));\n    for(k1 <- matrix.domain._1) {\n      val row: Row = sliceRows(matrix, k1);\n      val ln: Row = logAndNormalize(row);\n      for((k2,v) <- ln.pairsIterator) {\n        builder(k1 -> k2) = v;\n      }\n    }\n    builder.result;\n  }\n\n  /**\n   * Generates a vector of linearly spaced values between a and b (inclusive).\n   * The returned vector will have length elements, defaulting to 100.\n   */\n  def linspace(a : Double, b : Double, length : Int = 100) : DenseVectorCol[Double] = {\n    val increment = (b - a) / (length - 1);\n    DenseVectorCol.tabulate(length)(i => a + increment * i);\n  }\n\n}\n\nobject Library extends Library;\n"
  },
  {
    "path": "src/main/scala/scalala/library/LinearAlgebra.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\n\nimport org.netlib.lapack._\nimport org.netlib.util.intW\n\nimport operators._\nimport scalar.Scalar\nimport generic.collection.CanViewAsVector\nimport tensor.domain.TableDomain\nimport tensor.dense.{DenseVector, DenseMatrix}\nimport tensor.{DiagonalMatrix, MatrixSingularException, Matrix, Vector}\n\n\n/**\n * Basic linear algebraic operations.\n *\n * @author dlwh,dramage,retronym,afwlehmann,lancelet\n */\ntrait LinearAlgebra {\n\n  @inline private def requireNonEmptyMatrix[V](mat: Matrix[V]) =\n    if (mat.numCols == 0 || mat.numRows == 0)\n      throw new MatrixEmptyException\n\n  @inline private def requireSquareMatrix[V](mat: Matrix[V]) =\n    if (mat.numRows != mat.numCols)\n      throw new MatrixNotSquareException\n\n  @inline private def requireSymmetricMatrix[V](mat: Matrix[V]) = {\n    requireSquareMatrix(mat)\n\n    for (i <- 0 until mat.numRows; j <- 0 until i)\n      if (mat(i,j) != mat(j,i))\n        throw new MatrixNotSymmetricException\n  }\n\n  /**\n   * Eigenvalue decomposition (right eigenvectors)\n   *\n   * This function returns the real and imaginary parts of the eigenvalues,\n   * and the corresponding eigenvectors.  For most (?) interesting matrices,\n   * the imaginary part of all eigenvalues will be zero (and the corresponding\n   * eigenvectors will be real).  Any complex eigenvalues will appear in\n   * complex-conjugate pairs, and the real and imaginary components of the\n   * eigenvector for each pair will be in the corresponding columns of the\n   * eigenvector matrix.  Take the complex conjugate to find the second\n   * eigenvector.\n   *\n   * Based on EVD.java from MTJ 0.9.12\n   */\n  def eig(m : Matrix[Double]): (DenseVector[Double], DenseVector[Double], DenseMatrix[Double]) = {\n    requireNonEmptyMatrix(m)\n    requireSquareMatrix(m)\n\n    val n = m.numRows;\n\n    // Allocate space for the decomposition\n    var Wr = DenseVector.zeros[Double](n);\n    var Wi = DenseVector.zeros[Double](n);\n\n    var Vr = DenseMatrix.zeros[Double](n,n);\n\n    // Find the needed workspace\n    val worksize = Array.ofDim[Double](1);\n    val info = new intW(0);\n    LAPACK.getInstance.dgeev(\n      \"N\", \"V\", n,\n      Array.empty[Double], math.max(1,n),\n      Array.empty[Double], Array.empty[Double],\n      Array.empty[Double], math.max(1,n),\n      Array.empty[Double], math.max(1,n),\n      worksize, -1, info);\n\n    // Allocate the workspace\n    val lwork: Int = if (info.`val` != 0)\n      math.max(1,4*n);\n    else\n      math.max(1,worksize(0).toInt);\n\n    val work = Array.ofDim[Double](lwork);\n\n    // Factor it!\n\n    val A = new DenseMatrix(n,n,Array.ofDim[Double](n*n));\n    A := m\n    LAPACK.getInstance.dgeev(\n      \"N\", \"V\", n,\n      A.data, math.max(1,n),\n      Wr.data, Wi.data,\n      Array.empty[Double], math.max(1,n),\n      Vr.data, math.max(1,n),\n      work, work.length, info);\n\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n    else if (info.`val` < 0)\n      throw new IllegalArgumentException()\n\n    (Wr, Wi, Vr)\n  }\n\n  /**\n   * Computes the SVD of a m by n matrix\n   * Returns an m*m matrix U, a vector of singular values, and a n*n matrix V'\n   */\n  def svd(mat: DenseMatrix[Double]):(DenseMatrix[Double],DenseVector[Double],DenseMatrix[Double]) = {\n    requireNonEmptyMatrix(mat)\n\n    val m = mat.numRows;\n    val n = mat.numCols;\n    val S = DenseVector.zeros[Double](m min n);\n    val U = DenseMatrix.zeros[Double](m,m);\n    val Vt = DenseMatrix.zeros[Double](n,n);\n    val iwork = new Array[Int](8 * (m min n) );\n    val workSize = ( 3\n                    * math.min(m, n)\n                    * math.min(m, n)\n                    + math.max(math.max(m, n), 4 * math.min(m, n)\n                               * math.min(m, n) + 4 * math.min(m, n))\n                   );\n    val work = new Array[Double](workSize);\n    val info = new intW(0);\n    LAPACK.getInstance.dgesdd(\n      \"A\", m, n,\n      mat.copy.data, math.max(1,m),\n      S.data, U.data, math.max(1,m),\n      Vt.data, math.max(1,n),\n      work,work.length,iwork, info);\n\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n    else if (info.`val` < 0)\n      throw new IllegalArgumentException()\n\n    (U,S,Vt);\n  }\n\n  /**\n   * Returns the Kronecker product of the two matrices a and b,\n   * usually denoted a ⊗ b.\n   */\n  def kron[V1,V2,RV](a : Matrix[V1], b : Matrix[V2])(implicit mul : BinaryOp[V1,V2,OpMul,RV], s : Scalar[RV]) : Matrix[RV] = {\n    val builder = a.newBuilder[(Int,Int),RV](TableDomain(a.numRows * b.numRows, a.numCols * b.numCols));\n    a.foreachNonZeroTriple((ai,aj,av) => b.foreachNonZeroTriple((bi,bj,bv) =>\n      builder((ai * b.numRows + bi, aj * b.numCols + bj)) = mul(av, bv)));\n    builder.result.asInstanceOf[Matrix[RV]];\n  }\n\n  /**\n   * Returns the rank of each element in the given vector, adjusting for\n   * ties.\n   */\n  def ranks[X,V](x : X)(implicit xvt : CanViewAsVector[X,V], ord : Ordering[V]) : Array[Double] = {\n    val a = xvt(x);\n    val as = a.argsort;\n    val rv = new Array[Double](as.length);\n    var i = 0;\n    while (i < as.length) {\n      // count number of tied values at rank i\n      var numTiedValuesAtI = 1;\n      while (i + numTiedValuesAtI < as.length && a(as(i + numTiedValuesAtI)) == a(as(i))) {\n        numTiedValuesAtI += 1;\n      }\n\n      // set return value for next numTiedValuesAtI indexes in as\n      val rank = 1 + i + (numTiedValuesAtI - 1) / 2.0;\n      var j = 0;\n      while (j < numTiedValuesAtI) {\n        rv(as(i + j)) = rank;\n        j += 1;\n      }\n\n      i += numTiedValuesAtI;\n    }\n\n    rv;\n  }\n\n  /**\n   * The lower triangular portion of the given real quadratic matrix X. Note\n   * that no check will be performed regarding the symmetry of X.\n   */\n  def lowerTriangular[T: Scalar](X: Matrix[T]): DenseMatrix[T] = {\n      val N = X.numRows\n      val builder = X.newBuilder[(Int, Int), T](TableDomain(N, N))\n      for (i <- 0 until N; j <- 0 to i)\n        builder((i,j)) = X(i,j)\n      builder.result.asInstanceOf[DenseMatrix[T]]\n  }\n\n  /**\n   * The upper triangular portion of the given real quadratic matrix X. Note\n   * that no check will be performed regarding the symmetry of X.\n   */\n  def upperTriangular[T: Scalar](X: Matrix[T]): DenseMatrix[T] = {\n      val N = X.numRows\n      val builder = X.newBuilder[(Int, Int), T](TableDomain(N, N))\n      for (i <- 0 until N; j <- i until N)\n        builder((i,j)) = X(i,j)\n      builder.result.asInstanceOf[DenseMatrix[T]]\n  }\n\n  /**\n   * Computes the cholesky decomposition A of the given real symmetric\n   * positive definite matrix X such that X = A A^T.\n   *\n   * XXX: For higher dimensionalities, the return value really should be a\n   *      sparse matrix due to its inherent lower triangular nature.\n   */\n  def cholesky(X: Matrix[Double]): DenseMatrix[Double] = {\n    requireNonEmptyMatrix(X)\n\n    // As LAPACK doesn't check if the given matrix is in fact symmetric,\n    // we have to do it here (or get rid of this time-waster as long as\n    // the caller of this function is clearly aware that only the lower\n    // triangular portion of the given matrix is used and there is no\n    // check for symmetry).\n    requireSymmetricMatrix(X)\n\n    // Copy the lower triangular part of X. LAPACK will store the result in A\n    val A: DenseMatrix[Double] = lowerTriangular(X)\n\n    val N = X.numRows\n    val info = new intW(0)\n    LAPACK.getInstance.dpotrf(\n      \"L\" /* lower triangular */,\n      N /* number of rows */, A.data, math.max(1, N) /* LDA */,\n      info\n    )\n    // A value of info.`val` < 0 would tell us that the i-th argument\n    // of the call to dpotrf was erroneous (where i == |info.`val`|).\n    assert(info.`val` >= 0)\n\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n\n    A\n  }\n\n /**\n  * QR Factorization with pivoting\n  *\n  * input: A m x n matrix\n  * output: (Q,R,P,pvt) where AP = QR\n  *   Q: m x m\n  *   R: m x n\n  *   P: n x n : permutation matrix (P(pvt(i),i) = 1)\n  *   pvt : pivot indices\n  */\n  def qrp(A: DenseMatrix[Double]): (DenseMatrix[Double], DenseMatrix[Double], DenseMatrix[Int], Array[Int]) = {\n    val m = A.numRows\n    val n = A.numCols\n    val lapack = LAPACK.getInstance();\n\n    //Get optimal workspace size\n    // we do this by sending -1 as lwork to the lapack function\n    val work = new Array[Double](1)\n    var info = new intW(0)\n    lapack.dgeqrf(m, n, null, m, null, work, -1, info);\n    val lwork1 = if(info.`val` != 0) n else work(0).toInt\n    lapack.dorgqr(m, m, math.min(m,n), null, m, null, work, -1, info);\n    val lwork2 = if(info.`val` != 0) n else work(0).toInt;\n    //allocate workspace mem. as max of lwork1 and lwork3\n    val workspace = new Array[Double](math.max(lwork1, lwork2));\n\n    //Perform the QR factorization with dgep3\n    val maxd = math.max(m,n)\n    val AFact = DenseMatrix.zeros[Double](m,maxd)\n    val pvt = new Array[Int](n)\n    val tau = new Array[Double](math.min(m,n))\n    for(r <- 0 until m; c <- 0 until n) AFact(r,c) = A(r,c)\n      lapack.dgeqp3(m, n, AFact.data, m, pvt, tau, workspace, workspace.length, info);\n\n    //Error check\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n    else if (info.`val` < 0)\n      throw new IllegalArgumentException()\n\n    //Get R\n    val R = DenseMatrix.zeros[Double](m,n)\n\n    for(c <- 0 until maxd if(c < n);\n        r <- 0 until m if(r <= c))\n        R(r,c) = AFact(r,c)\n\n    //Get Q from the matrix returned by dgep3\n    val Q = DenseMatrix.zeros[Double](m,m)\n    lapack.dorgqr(m, m, math.min(m,n), AFact.data, m, tau, workspace, workspace.length, info);\n    for(r <- 0 until m;\n        c <- 0 until maxd if(c < m))\n        Q(r,c) = AFact(r,c)\n\n    //Error check\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n    else if (info.`val` < 0)\n      throw new IllegalArgumentException()\n\n    //Get P\n    for(i <- 0 until pvt.length) pvt(i)-=1\n    val P = DenseMatrix.zeros[Int](n,n)\n    for(i <- 0 until n)\n      P(pvt(i), i) = 1\n\n    (Q,R,P,pvt)\n  }\n\n  /**\n  * QR Factorization\n  *\n  * input: A m x n matrix\n  * optional: skipQ - if true, don't reconstruct orthogonal matrix Q (instead returns (null,R))\n  * output: (Q,R)\n  *   Q: m x m\n  *   R: m x n\n  */\n  def qr(A: DenseMatrix[Double], skipQ : Boolean = false): (DenseMatrix[Double], DenseMatrix[Double]) = {\n    val m = A.numRows\n    val n = A.numCols\n    val lapack = LAPACK.getInstance();\n\n    //Get optimal workspace size\n    // we do this by sending -1 as lwork to the lapack function\n    val work = new Array[Double](1)\n    var info = new intW(0)\n    lapack.dgeqrf(m, n, null, m, null, work, -1, info);\n    val lwork1 = if(info.`val` != 0) n else work(0).toInt\n    lapack.dorgqr(m, m, math.min(m,n), null, m, null, work, -1, info);\n    val lwork2 = if(info.`val` != 0) n else work(0).toInt;\n    //allocate workspace mem. as max of lwork1 and lwork3\n    val workspace = new Array[Double](math.max(lwork1, lwork2));\n\n    //Perform the QR factorization with dgeqrf\n    val maxd = math.max(m,n)\n    val mind = math.max(m,n)\n    val tau = new Array[Double](mind)\n    val outputMat = DenseMatrix.zeros[Double](m,maxd)\n    for(r <- 0 until m; c <- 0 until n)\n      outputMat(r,c) = A(r,c)\n    lapack.dgeqrf(m, n, outputMat.data, m, tau, workspace, workspace.length, info);\n\n    //Error check\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n    else if (info.`val` < 0)\n      throw new IllegalArgumentException()\n\n    //Get R\n    val R = DenseMatrix.zeros[Double](m,n)\n    for(c <- 0 until maxd if(c < n); r <- 0 until m if(r <= c))\n      R(r,c) = outputMat(r,c)\n\n    //unless the skipq flag is set\n    if(!skipQ){\n      //Get Q from the matrix returned by dgep3\n      val Q = DenseMatrix.zeros[Double](m,m)\n      lapack.dorgqr(m, m, math.min(m,n), outputMat.data, m, tau, workspace, workspace.length, info);\n      for(r <- 0 until m;\n          c <- 0 until maxd if(c < m))\n        Q(r,c) = outputMat(r,c)\n\n      //Error check\n      if (info.`val` > 0)\n        throw new NotConvergedException(NotConvergedException.Iterations)\n      else if (info.`val` < 0)\n        throw new IllegalArgumentException()\n      (Q,R)\n    }\n    //skip Q and just return R\n    else (null,R)\n  }\n\n\n\n\n  /**\n   * Computes all eigenvalues (and optionally right eigenvectors) of the given\n   * real symmetric matrix X.\n   */\n  def eigSym(X: Matrix[Double], rightEigenvectors: Boolean):\n    (DenseVector[Double], Option[DenseMatrix[Double]]) =\n  {\n    requireNonEmptyMatrix(X)\n\n    // As LAPACK doesn't check if the given matrix is in fact symmetric,\n    // we have to do it here (or get rid of this time-waster as long as\n    // the caller of this function is clearly aware that only the lower\n    // triangular portion of the given matrix is used and there is no\n    // check for symmetry).\n    requireSymmetricMatrix(X)\n\n    // Copy the lower triangular part of X. LAPACK will store the result in A.\n    val A     = lowerTriangular(X)\n\n    val N     = X.numRows\n    val evs   = DenseVector.zeros[Double](N)\n    val lwork = math.max(1, 3*N-1)\n    val work  = Array.ofDim[Double](lwork)\n    val info  = new intW(0)\n    LAPACK.getInstance.dsyev(\n      if (rightEigenvectors) \"V\" else \"N\" /* eigenvalues N, eigenvalues & eigenvectors \"V\" */,\n      \"L\" /* lower triangular */,\n      N /* number of rows */, A.data, math.max(1, N) /* LDA */,\n      evs.data,\n      work /* workspace */, lwork /* workspace size */,\n      info\n    )\n    // A value of info.`val` < 0 would tell us that the i-th argument\n    // of the call to dsyev was erroneous (where i == |info.`val`|).\n    assert(info.`val` >= 0)\n\n    if (info.`val` > 0)\n      throw new NotConvergedException(NotConvergedException.Iterations)\n\n    (evs, if (rightEigenvectors) Some(A) else None)\n  }\n\n  /**\n   * Computes the LU factorization of the given real M-by-N matrix X such that\n   * X = P * L * U where P is a permutation matrix (row exchanges).\n   *\n   * Upon completion, a tuple consisting of a matrix A and an integer array P.\n   *\n   * The upper triangular portion of A resembles U whereas the lower triangular portion of\n   * A resembles L up to but not including the diagonal elements of L which are\n   * all equal to 1.\n   *\n   * For 0 <= i < M, each element P(i) denotes whether row i of the matrix X\n   * was exchanged with row P(i-1) during computation (the offset is caused by\n   * the internal call to LAPACK).\n   */\n  def LU[T](X: Matrix[T])(implicit td: T => Double): (DenseMatrix[Double], Array[Int]) = {\n    requireNonEmptyMatrix(X)\n\n    val M    = X.numRows\n    val N    = X.numCols\n    val Y    = DenseMatrix.tabulate[Double](M,N)(X(_,_))\n    val ipiv = Array.ofDim[Int](math.min(M,N))\n    val info = new intW(0)\n    LAPACK.getInstance.dgetrf(\n      M /* numRows */, N /* numCols */,\n      Y.data, math.max(1,M) /* LDA */,\n      ipiv /* pivot indices */,\n      info\n    )\n    // A value of info.`val` < 0 would tell us that the i-th argument\n    // of the call to dsyev was erroneous (where i == |info.`val`|).\n    assert(info.`val` >= 0)\n\n    (Y, ipiv)\n  }\n\n  /**\n   * Computes the determinant of the given real matrix.\n   */\n  def det[T](X: Matrix[T])(implicit td: T => Double): Double = {\n    requireSquareMatrix(X)\n\n    // For triangular N-by-N matrices X, the determinant of X equals the product\n    // of the diagonal elements X(i,i) where 0 <= i < N.\n    // Since det(AB) = det(A) * det(B), the LU factorization is well-suited for\n    // the computation of the determinant of general N-by-N matrices.\n    val (m, ipiv) = LU(X)\n\n    // Count the number of exchanged rows.  ipiv contains an array of swapped indices,\n    //  but it also contains indices that weren't swapped.  To count the swapped\n    //  indices, we have to compare them against their position within the array.  A\n    //  final complication is that the array indices are 1-based, due to the LU call\n    //  into LAPACK.\n    val numExchangedRows = ipiv.map(_ - 1).zipWithIndex.count { piv => piv._1 != piv._2 }\n\n    var acc = if (numExchangedRows % 2 == 1) -1.0 else 1.0\n    for (i <- 0 until m.numRows)\n      acc *= m(i,i)\n\n    acc\n  }\n\n  /**\n   * Computes the inverse of a given real matrix.\n   */\n  def inv[T](X: Matrix[T])(implicit td: T => Double): DenseMatrix[Double] = {\n    requireSquareMatrix(X)\n\n    val (m, ipiv) = LU(X)\n    val N         = m.numRows\n    val lwork     = math.max(1, N)\n    val work      = Array.ofDim[Double](lwork)\n    val info      = new intW(0)\n    LAPACK.getInstance.dgetri(\n      N, m.data, math.max(1, N) /* LDA */,\n      ipiv,\n      work /* workspace */, lwork /* workspace size */,\n      info\n    )\n    assert(info.`val` >= 0, \"Malformed argument %d (LAPACK)\".format(-info.`val`))\n\n    if (info.`val` > 0)\n      throw new MatrixSingularException\n\n    m\n  }\n\n  /**\n   * Computes the Moore-Penrose pseudo inverse of the given real matrix X.\n   */\n  def pinv(X: DenseMatrix[Double]) : DenseMatrix[Double] = {\n    requireNonEmptyMatrix(X)\n\n    // The pseudo inverse is nothing but the least-squares solution to AX=B,\n    // hence:\n    //       d/dX 1/2 (AX-B)^2 = A^T (AX-B)\n    // Solving A^T (AX-B) = 0 for X yields\n    //       A^T AX = A^T B\n    //    =>      X = (A^T A)^(-1) A^T B\n\n    inv(X.t * X) * X.t\n  }\n\n  /**\n   * Computes the Moore-Penrose pseudo inverse of the given real matrix X.\n   */\n  def pinv[V](X: DenseMatrix[V])(implicit cast : V=>Double) : DenseMatrix[Double] = {\n    requireNonEmptyMatrix(X)\n\n    // The pseudo inverse is nothing but the least-squares solution to AX=B,\n    // hence:\n    //       d/dX 1/2 (AX-B)^2 = A^T (AX-B)\n    // Solving A^T (AX-B) = 0 for X yields\n    //       A^T AX = A^T B\n    //    =>      X = (A^T A)^(-1) A^T B\n\n    pinv(X.mapValues(cast));\n  }\n\n  /**\n   * A diagonal matrix whose elements are specified by the given vector.\n   */\n  def diag[S](v: scalala.tensor.Vector[S])(implicit s: Scalar[S]): DiagonalMatrix[Vector[S], S] =\n    new DiagonalMatrix(v)\n\n  /**\n   * Vector cross product of 3D vectors a and b.\n   */\n  def cross[V1, V2, RV](a: DenseVector[V1], b: DenseVector[V2])(\n    implicit mul: BinaryOp[V1, V2, OpMul, RV],\n    sub: BinaryOp[RV, RV, OpSub, RV],\n    s: Scalar[RV]\n  ): DenseVector[RV] = {\n    require(a.length == 3)\n    require(b.length == 3)\n    DenseVector[RV](\n      sub(mul(a(1), b(2)), mul(a(2), b(1))),\n      sub(mul(a(2), b(0)), mul(a(0), b(2))),\n      sub(mul(a(0), b(1)), mul(a(1), b(0)))\n    )\n  }\n\n  /**\n   * Computes the rank of a DenseMatrix[Double].\n   *\n   * The rank of the matrix is computed using the SVD method.  The singular values of the SVD\n   * which are greater than a specified tolerance are counted.\n   *\n   * @param m matrix for which to compute the rank\n   * @param tol optional tolerance for singular values.  If not supplied, the default\n   *   tolerance is: max(m.numCols, m.numRows) * eps * sigma_max, where\n   *   eps is the machine epsilon and sigma_max is the largest singular value of m.\n   * @return the rank of the matrix (number of singular values)\n   */\n  def rank(m: DenseMatrix[Double], tol: Option[Double] = None): Int = {    \n    val (u, s, vt) = svd(m)\n    val useTol = tol.getOrElse {\n      // we called LAPACK for the SVD method, so this is the LAPACK definition of eps.\n      val eps: Double = 2.0 * LAPACK.getInstance.dlamch(\"e\")\n      math.max(m.numCols, m.numRows) * eps * s.max\n    }\n    s.data.count(_ > useTol)  // TODO: Use DenseVector[_].count() if/when that is implemented\n  }\n\n}\n\nobject LinearAlgebra extends LinearAlgebra;\n\n\n/**\n * Exception thrown if a routine has not converged.\n */\nclass NotConvergedException(val reason: NotConvergedException.Reason, msg: String = \"\")\nextends RuntimeException(msg)\n\nobject NotConvergedException {\n  trait Reason;\n  object Iterations extends Reason;\n  object Divergence extends Reason;\n  object Breakdown extends Reason;\n}\n\nclass MatrixNotSymmetricException\nextends IllegalArgumentException(\"Matrix is not symmetric\");\n\nclass MatrixNotSquareException\nextends IllegalArgumentException(\"Matrix is not square\");\n\nclass MatrixEmptyException\nextends IllegalArgumentException(\"Matrix is empty\");\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/Numerics.scala",
    "content": "/*\n Copyright 2009 David Hall, Daniel Ramage\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\npackage scalala.library\n\nimport math._\nimport scalala.tensor.Tensor1\n\n/**\n * Provides some functions left out of java.lang.math.\n *\n * Borrowed from scalanlp.\n *\n * @author dlwh, afwlehmann\n */\ntrait Numerics {\n\n  /**\n   * The standard digamma function. Cribbed from Radford Neal\n   *\n   * http://google.com/codesearch/p?hl=en#EbB356_xxkI/fbm.2003-06-29/util/digamma.c\n   */\n  def digamma(xx: Double) = {\n    var x = xx;\n    var r = 0.0;\n\n    while (x<=5) {\n      r -= 1/x;\n      x += 1;\n    }\n\n    val f = 1d/(x * x);\n    val t = f*(-1/12.0 +\n            f*(1/120.0 +\n            f*(-1/252.0 +\n            f*(1/240.0 +\n            f*(-1/132.0 +\n            f*(691/32760.0 +\n            f*(-1/12.0 +\n            f*3617.0/8160.0)))))));\n    r + log(x) - 0.5/x + t;\n  }\n\n  private val cof =  Array(76.18009172947146, -86.50532032941677,\n    24.01409824083091,-1.231739572450155,\n    0.1208650973866179e-2,-0.5395239384953e-5\n  );\n\n  /**\n   * Evaluates the log of the generalized beta function.\n   *  = \\sum_a lgamma(c(a))- lgamma(c.sum)\n   */\n  def lbeta[T](c: Tensor1[T,Double]) = {\n    c.valuesIterator.foldLeft(-lgamma(c.sum))( (acc,x)=> acc +lgamma(x));\n  }\n\n  /**\n  * Computes the log of the gamma function.\n  *\n  * Reference: Numerical Recipes in C\n  * http://www.library.cornell.edu/nr/cbookcpdf.html\n  * www.cs.berkeley.edu/~milch/blog/versions/blog-0.1.3/blog/distrib\n  * @return an approximation of the log of the Gamma function * of x.  Laczos Approximation\n  */\n  def lgamma(x : Double) = {\n    var y = x;\n    var tmp = x + 5.5;\n    tmp -= ((x + 0.5) * log(tmp));\n    var ser = 1.000000000190015;\n    var j = 0;\n    while (j < 6) {\n      y += 1;\n      ser += (cof(j)/y);\n      j +=1;\n    }\n    (-tmp + log(2.5066282746310005*ser / x));\n  }\n\n  // erf and erfi: cribbed from http://en.wikipedia.org/wiki/Error_function\n  private val erf_a = 0.147\n  /**\n   * An approximation to the error function\n   */\n  def erf(x: Double) = {\n    val x2 = x*x\n    val inner = exp(-1*x2*(4/Pi + erf_a*x2) /\n                    (1.0 + erf_a*x2))\n    signum(x)*sqrt(1.0 - inner)\n  }\n\n  def erfi(x: Double) = {\n    val x2 = x*x\n    val i1 = 2.0/(Pi*erf_a) + log(1-x2)/2.0\n    val i2 = log(1-x2)/erf_a\n    signum(x) * sqrt( sqrt(i1*i1 - i2) - i1 )\n  }\n\n  /**\n  * Incomplete lgamma function.\n  */\n  def lgamma(a: Double, z:Double) = {\n    var res = 0d;\n    var m = 21\n    while( m > 1) {\n      res = ((1.0-m)*(m-1.0-a)) / (2*m -1+z -a + res);\n      m -= 1\n    }\n\n    a * log(z) - z - log(1+z-a+res);\n  }\n\n  /**\n  * Incomplete gamma function, the exp of lgamma(a,z)\n  */\n  def gamma(a: Double, z:Double) = exp(lgamma(a,z));\n\n  /**\n  * Sums together things in log space.\n  * @return log(exp(a) + exp(b))\n  */\n  def logSum(a: Double, b: Double) = {\n    if (a.isNegInfinity) b\n    else if (b.isNegInfinity) a\n    else if (a < b) b + log1p(exp(a - b))\n    else a + log1p(exp(b - a))\n  }\n\n  /**\n  * Sums together things in log space.\n  * @return log(\\sum exp(a_i))\n  */\n  def logSum(a: Double, b: Double, c: Double*): Double = {\n    if (c.length == 0)\n      logSum(a, b)\n    else\n      logSum(logSum(a, b) +: c)\n  }\n\n  /**\n  * Sums together things in log space.\n  * @return log(\\sum exp(a_i))\n  */\n  def logSum(iter: Iterator[Double], max: Double): Double = {\n    require(iter.hasNext)\n    if (max.isInfinite) {\n      max\n    } else {\n      val aux = (0.0 /: iter) {\n        (acc, x) => if (x.isNegInfinity) acc else acc + math.exp(x-max)\n      }\n      if (aux != 0)\n        max + log(aux)\n      else\n        max\n    }\n  }\n\n  /**\n  * Sums together things in log space.\n  * @return log(\\sum exp(a_i))\n  */\n  def logSum(a: Seq[Double]): Double = {\n    a.length match {\n      case 0 => Double.NegativeInfinity\n      case 1 => a(0)\n      case 2 => logSum(a(0), a(1))\n      case _ => logSum(a.iterator, a reduceLeft (_ max _))\n    }\n  }\n\n  /**\n   * Sums together the first length elements in log space.\n   * The length parameter is used to make things faster.\n   *\n   * This method needs to be fast. Don't scala-ify it.\n   * @return log(\\sum^length exp(a_i))\n   */\n  def logSum(a: Array[Double], length: Int):Double = {\n    length match {\n      case 0 => Double.NegativeInfinity;\n      case 1 => a(0)\n      case 2 => logSum(a(0),a(1));\n      case _ =>\n        val m = max(a, length);\n        if(m.isInfinite) m\n        else {\n          var i = 0;\n          var accum = 0.0;\n          while(i < length) {\n            accum += exp(a(i) - m);\n            i += 1;\n          }\n          m + log(accum);\n        }\n    }\n  }\n\n  // fast versions of max. Useful for the fast logsum.\n  private def max(a: Array[Double], length: Int) = {\n    var i = 1;\n    var max =  a(0);\n    while(i < length) {\n      if(a(i) > max) max = a(i);\n      i += 1;\n    }\n    max;\n\n  }\n\n  /**\n   * The sigmoid function: 1/(1 + exp(-x));\n   */\n  def sigmoid(x: Double) = 1/(1+exp(-x));\n\n\n  /**\n   * Takes the difference of two doubles in log space. Requires a &gt b.\n   * Note that this only works if a and b are close in value. For a &gt;&gt; b,\n   * this will almost certainly do nothing. (exp(30) - exp(1) \\approx exp(30))\n   *\n   * @return log(exp(a) - exp(b))\n   */\n  def logDiff(a: Double, b: Double): Double = {\n    require(a >= b)\n    if (a > b) a + math.log(1.0 - math.exp(b-a))\n    else Double.NegativeInfinity\n  }\n\n  /**\n   * Computes the polynomial P(x) with coefficients given in the passed in array.\n   * coefs(i) is the coef for the x^i term.\n   */\n  def poly(coefs: Array[Double], x: Double) = {\n    var i = coefs.length-1;\n    var p = coefs(i);\n    while (i>0) {\n      i -= 1;\n      p = p*x + coefs(i);\n    }\n    p\n  }\n\n}\n\nobject Numerics extends Numerics\n"
  },
  {
    "path": "src/main/scala/scalala/library/Plotting.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\n\nimport generic.collection.{CanViewAsTensor1,CanViewAsTensor2};\n\nimport plotting._;\n\nimport java.awt.Color;\n\n/**\n * Matlab-like plotting routines.\n *\n * @author dramage\n */\ntrait Plotting {\n\n  /** Returns the default figure set. */\n  def figures = Figures.global;\n\n  /** Selects and returns the requested figure by index (1-based). */\n  def figure(select:Int = -1)(implicit figures : Figures = figures) : Figure = {\n    if (select >= 0) {\n      figures.figure = select;\n      figures.figure.refresh;\n    }\n    return figures.figure\n  }\n\n  /** Returns the current figure. */\n  def figure : Figure =\n    figure();\n\n  /** Clears the current figure */\n  def clf()(implicit figure : Figure = figures.figure) = {\n    figure.clear;\n  }\n\n  /** Returns the current plot in the current figure. */\n  def plot : XYPlot =\n    figure.plot;\n\n  /** Selects the given subplot.  Note that select is 1-based for compatibility with matlab. */\n  def subplot(rows:Int,cols:Int,select:Int)(implicit figure : Figure = figure) : XYPlot = {\n    figure.rows = rows;\n    figure.cols = cols;\n    figure.plot = select - 1;\n    figure.refresh;\n    return figure.plot;\n  }\n\n  /** Sets the title of this figure. */\n  def title(title : String)(implicit xyplot : XYPlot = plot) {\n    xyplot.title = title;\n  }\n\n  /** Sets the label of the x axis */\n  def xlabel(text : String)(implicit xyplot : XYPlot = plot) {\n    xyplot.xaxis.setLabel(text);\n  }\n\n  /** Sets the label of the y axis */\n  def ylabel(text : String)(implicit xyplot : XYPlot = plot) {\n    xyplot.yaxis.setLabel(text);\n  }\n\n  /** Sets the lower and upper bounds of the current plot. */\n  def xlim(xmin : Double, xmax : Double)(implicit xyplot : XYPlot = figures.figure.plot) {\n    xyplot.plot.getDomainAxis.setLowerBound(xmin);\n    xyplot.plot.getDomainAxis.setUpperBound(xmax);\n  }\n\n  /** Sets the lower and upper bounds of the current plot. */\n  def ylim(ymin : Double, ymax : Double)(implicit xyplot : XYPlot = figures.figure.plot) {\n    xyplot.plot.getRangeAxis.setLowerBound(ymin);\n    xyplot.plot.getRangeAxis.setUpperBound(ymax);\n  }\n\n  /** For re-plotting to same figure */\n  def hold(state : Boolean)(implicit xyplot : XYPlot = figures.figure.plot) : Unit = {\n    plot.hold = state;\n  }\n\n  /** Saves the current figure at the requested dpi to the given filename. */\n  def saveas(filename : String, dpi : Int = 72)(implicit figure : Figure = figure) : Unit = {\n    // make sure figure is visible or saved image will come up empty\n    figure.refresh();\n    \n    plotting.ExportGraphics.writeFile(\n      new java.io.File(filename),\n      draw = figure.drawPlots _,\n      width = figure.contents.getWidth,\n      height = figure.contents.getHeight,\n      dpi = dpi);\n  }\n\n  /**\n   * Plots the given y versus the given x with the given style.\n   *\n   * @param x X-coordinates, co-indexed with y (and indexed by keys of type K).\n   * @param y Y-coordinates, co-indexed with x (and indexed by keys of type K).\n   * @param style Matlab-like style spec of the series to plot.\n   * @param name Name of the series to show in the legend.\n   * @param labels Optional in-graph labels for some points.\n   * @param tips Optional mouse-over tooltips for some points.\n   */\n  def plot[K,X,XV,Y,YV]\n  (x : X, y : Y, style : Char = '-', colorcode : String = null, name : String = null,\n  lines : Boolean = true, shapes : Boolean = false)\n   // labels : PartialFunction[K,String] = null.asInstanceOf[PartialFunction[K,String]],\n   // tips : PartialFunction[K,String] = null.asInstanceOf[PartialFunction[K,String]])\n  (implicit xyplot : XYPlot = figures.figure.plot,\n   xtv : CanViewAsTensor1[X,K,XV], ytv : CanViewAsTensor1[Y,K,YV]) : Unit = {\n\n    val series = xyplot.nextSeries;\n\n    val xt = xtv(x);\n    val yt = ytv(y);\n\n    val labels : PartialFunction[K,String] = null;\n    val tips : PartialFunction[K,String] = null;\n\n    require(xt.domain == yt.domain, \"x and y must have same domain\");\n\n    val items = xt.domain.toIndexedSeq;\n\n    // initialize dataset\n    val dataset = XYDataset(\n      items = items,\n      name = if (name == null) \"Series \"+series else name,\n      x = (k : K) => xt.scalar.toDouble(xt(k)),\n      y = (k : K) => yt.scalar.toDouble(yt(k)),\n      label = (k : K) => if (labels != null && labels.isDefinedAt(k)) labels(k) else null,\n      tip = (k : K) => if (tips != null && tips.isDefinedAt(k)) tips(k) else null\n    );\n\n    // initialize the series renderer\n    val renderer = new org.jfree.chart.renderer.xy.XYLineAndShapeRenderer();\n\n    if (colorcode != null) {\n      val color = PaintScale.convertToColor(colorcode);\n      renderer.setSeriesPaint(0, color);\n      renderer.setSeriesFillPaint(0, color);\n      renderer.setSeriesOutlinePaint(0, color);\n    } else {\n      renderer.setSeriesPaint(0, XYPlot.paint(series));\n      renderer.setSeriesFillPaint(0, XYPlot.fillPaint(series));\n      renderer.setSeriesOutlinePaint(0, XYPlot.outlinePaint(series));\n    }\n    renderer.setSeriesStroke(0, XYPlot.stroke(series));\n    renderer.setSeriesShape(0, XYPlot.shape(series));\n    renderer.setSeriesOutlineStroke(0, XYPlot.outlineStroke(series));\n\n    val tooltipGenerator = new org.jfree.chart.labels.XYToolTipGenerator() {\n      override def generateToolTip(dataset : org.jfree.data.xy.XYDataset,\n        series : Int, item : Int) : String = {\n        dataset.asInstanceOf[XYDataset[_]].getTip(series, item);\n      }\n    }\n    renderer.setSeriesToolTipGenerator(series, tooltipGenerator);\n\n    val labelGenerator = new org.jfree.chart.labels.XYItemLabelGenerator() {\n      override def generateLabel(dataset : org.jfree.data.xy.XYDataset,\n        series : Int, item : Int) : String = {\n        dataset.asInstanceOf[XYDataset[_]].getLabel(series, item);\n      }\n    }\n    renderer.setSeriesItemLabelGenerator(series, labelGenerator);\n    renderer.setSeriesItemLabelsVisible(series, labels != null);\n\n    style match {\n      case '-' =>\n        // default line type\n        renderer.setSeriesLinesVisible(0,lines);\n        renderer.setSeriesShapesVisible(0,shapes);\n      case '.' =>\n        renderer.setSeriesLinesVisible(0,false);\n        renderer.setSeriesShapesVisible(0,true);\n        renderer.setSeriesShape(0,XYPlot.dot);\n      case '+' =>\n        renderer.setSeriesLinesVisible(0,false);\n        renderer.setSeriesShapesVisible(0,true);\n        renderer.setSeriesShape(0,XYPlot.plus);\n      case _ =>\n        throw new IllegalArgumentException(\"Expected style to be one of - . or +\")\n    }\n\n    // set standard tick unit back to default (non-int) if we see non-ints\n    if (!xt.scalar.zero.isInstanceOf[Int]) xyplot.setXAxisDecimalTickUnits();\n    if (!yt.scalar.zero.isInstanceOf[Int]) xyplot.setYAxisDecimalTickUnits();\n\n    // add dataset and renderer to plot\n    xyplot.plot.setDataset(series, dataset);\n    xyplot.plot.setRenderer(series, renderer);\n    xyplot.refresh();\n  }\n\n  /**\n   * Displays a scatter plot of x versus y, each point drawn at the given\n   * size and mapped with the given color.\n   *\n   * Example usage: https://gist.github.com/1288473\n   *\n   * @param x The x coordinates to draw as provided by anything that can be seen as a Tensor1.\n   * @param y The y coordinates to draw as provided by anything that can be seen as a Tensor1.\n   * @param s The size of each circle (on the same scale as the domain axis);\n   * @param c A partial function (e.g. a Map) from item ids to the color to draw the bubble.\n   *   Missing colors are drawn with a hashed pattern.\n   * @param labels Labels to draw next to each point.\n   * @param tips Tooltips to show on mouseover for each point.\n   * @param name Series name for legend\n   */\n  def scatter[K,X,XV,Y,YV,S,SV]\n  (x : X, y : Y, size : S,\n   colors : PartialFunction[K,java.awt.Paint],\n   labels : PartialFunction[K,String] = null.asInstanceOf[PartialFunction[K,String]],\n   tips : PartialFunction[K,String] = null.asInstanceOf[PartialFunction[K,String]],\n   name : String = null)\n  (implicit xyplot : XYPlot = figures.figure.plot,\n   xtv : CanViewAsTensor1[X,K,XV], ytv : CanViewAsTensor1[Y,K,YV],\n   stv : CanViewAsTensor1[S,K,SV])\n  : Unit = {\n\n    val series = xyplot.nextSeries;\n\n    val (xt,yt,st) = (xtv(x), ytv(y), stv(size));\n    require(xt.domain == yt.domain, \"x and y must have same domain\");\n\n    val items = xt.domain.toIndexedSeq;\n\n    val paintScale = CategoricalPaintScale[K](colors);\n\n    // initialize dataset\n    val dataset = XYZDataset(\n      items = items,\n      name = if (name == null) \"Series \"+series else name,\n      x = (k : K) => xt.scalar.toDouble(xt(k)),\n      y = (k : K) => yt.scalar.toDouble(yt(k)),\n      z = (k : K) => st.scalar.toDouble(st(k)),\n      label = (k : K) => if (labels != null && labels.isDefinedAt(k)) labels(k) else null,\n      tip = (k : K) => if (tips != null && tips.isDefinedAt(k)) tips(k) else null\n    );\n\n    // initialize the series renderer\n    import org.jfree.chart.renderer.xy.XYBubbleRenderer;\n    val renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_DOMAIN_AXIS) {;\n      val stroke = new java.awt.BasicStroke(0f);\n      override def getItemPaint(series : Int, item : Int) : java.awt.Paint =\n        paintScale(items(item));\n      override def getItemStroke(series : Int, item : Int) = stroke;\n    }\n\n    val tooltipGenerator = new org.jfree.chart.labels.XYToolTipGenerator() {\n      override def generateToolTip(dataset : org.jfree.data.xy.XYDataset, series : Int, item : Int) : String = {\n        dataset.asInstanceOf[XYZDataset[_]].getTip(0, item);\n      }\n    }\n    renderer.setSeriesToolTipGenerator(series, tooltipGenerator);\n\n    val labelGenerator = new org.jfree.chart.labels.BubbleXYItemLabelGenerator() {\n      override def generateLabel(dataset : org.jfree.data.xy.XYDataset, series : Int, item : Int) : String = {\n        dataset.asInstanceOf[XYZDataset[_]].getLabel(0, item);\n      }\n    }\n    renderer.setSeriesItemLabelGenerator(series, labelGenerator);\n    renderer.setSeriesItemLabelsVisible(series, labels != null);\n\n    // set standard tick unit back to default (non-int) if we see non-ints\n    if (!xt.scalar.zero.isInstanceOf[Int]) xyplot.setXAxisDecimalTickUnits();\n    if (!yt.scalar.zero.isInstanceOf[Int]) xyplot.setYAxisDecimalTickUnits();\n\n    // add dataset and renderer to plot\n    xyplot.plot.setDataset(series, dataset);\n    xyplot.plot.setRenderer(series, renderer);\n    xyplot.refresh();\n  }\n\n//  /** An XY stacked area chart. */\n//  def stacked(x : Vector, y : Seq[Vector], names : Seq[String])(implicit xyplot : XYPlot = _figures.figure.plot) {\n//    import org.jfree.data.xy.{AbstractXYDataset, TableXYDataset};\n//    val dataset = new AbstractXYDataset with TableXYDataset {\n//      override def getX(series : Int, item : Int) = x(item);\n//      override def getY(series : Int, item : Int) = y(series)(item);\n//      override def getSeriesKey(series : Int) = names(series);\n//      override def getSeriesCount = y.size;\n//      override def getItemCount = x.size;\n//      override def getItemCount(series : Int) = y(series).size;\n//    };\n//\n//    import org.jfree.chart.renderer.xy.StackedXYAreaRenderer2;\n//\n//    val renderer = new StackedXYAreaRenderer2(null,null);\n//    renderer.setOutline(true);\n//\n//    // add dataset and renderer\n//    val series = xyplot.nextSeries;\n//    xyplot.plot.setDataset(series,dataset);\n//    xyplot.plot.setRenderer(series, renderer);\n//    xyplot.refresh;\n//  }\n//\n//  /** An XY stacked area chart with default names. */\n//  def stacked(x : Vector, y : Seq[Vector])(implicit xyplot : XYPlot = _figures.figure.plot) {\n//    stacked(x, y, y.iterator.zipWithIndex.map(_._2.toString).toSeq)(xyplot);\n//  }\n\n  /** Plots a histogram of the given data into the given number of bins */\n  def hist[D,K,V](data : D, bins : HistogramBins = 10, name : String = \"Histogram\")\n  (implicit xyplot : XYPlot = plot, dtv : CanViewAsTensor1[D,K,V]) : Unit = {\n    val dt = dtv(data);\n    implicit def dvToDouble(v : V) = dt.scalar.toDouble(v);\n\n    val binner : StaticHistogramBins = bins match {\n      case static : StaticHistogramBins => static;\n      case dynamic : DynamicHistogramBins =>\n        dynamic(dt.min, dt.max);\n    }\n\n    val counts = new Array[Int](binner.splits.length + 1);\n    for (value <- dt.valuesIterator) {\n      counts(binner.bin(value)) += 1;\n    }\n\n    val width = (binner.splits.iterator zip binner.splits.iterator.drop(1)).map(tup => tup._2 - tup._1).min;\n\n    val dataset = new org.jfree.data.xy.XYBarDataset(\n      XYDataset(\n        name = name,\n        items = IndexedSeq.range(0,counts.length),\n        x = (i : Int) =>\n          if (i == binner.splits.length) {\n            binner.splits(i - 1) + width / 2.0\n          } else {\n            binner.splits(i) - width / 2.0\n          },\n        y = (i : Int) => counts(i),\n        label = (i : Int) => null,\n        tip = (i : Int) => null\n      ), width);\n\n    val series = xyplot.nextSeries;\n\n    val renderer = new org.jfree.chart.renderer.xy.XYBarRenderer;\n    renderer.setSeriesPaint(0, XYPlot.paint(series));\n    renderer.setSeriesShape(0, XYPlot.shape(series));\n    renderer.setSeriesStroke(0, XYPlot.stroke(series));\n    renderer.setSeriesFillPaint(0, XYPlot.fillPaint(series));\n    renderer.setSeriesOutlinePaint(0, XYPlot.outlinePaint(series));\n    renderer.setSeriesOutlineStroke(0, XYPlot.outlineStroke(series));\n    renderer.setShadowVisible(false);\n    renderer.setBarPainter(new org.jfree.chart.renderer.xy.StandardXYBarPainter());\n\n    xyplot.plot.getDomainAxis.setLowerBound(binner.splits(0)-width/2.0);\n    xyplot.plot.getDomainAxis.setUpperBound(binner.splits(binner.splits.length-1)+width/2.0);\n\n    // set standard tick unit back to default (non-int)\n    xyplot.setXAxisDecimalTickUnits();\n    xyplot.setYAxisDecimalTickUnits();\n\n    xyplot.plot.setDataset(series,dataset);\n    xyplot.plot.setRenderer(series,renderer);\n    xyplot.refresh();\n  }\n\n  /**\n   * Displays an image in the current figure, where each cell in the matrix\n   * provides color for one square of the image.\n   *\n   * @param img A matrix containing the colors to plot\n   * @param scale Scale used for converting matrix values to colors.\n   * @param showScale If true, show the paint scale legend\n   * @param name Series name\n   * @param offset Offset for indexing the top-left corner of the matrix\n   * @param labels Labels for some subset of the data points\n   * @param tips Tooltip popups for some subset of the data points\n   */\n  def image[M,V]\n  (img : M,\n   scale : GradientPaintScale[Double] = null,\n   showScale : Boolean = true,\n   name : String = null,\n   offset : (Int,Int) = (0,0),\n   labels : PartialFunction[(Int,Int), String] = null.asInstanceOf[PartialFunction[(Int,Int), String]],\n   tips : PartialFunction[(Int,Int), String] = null.asInstanceOf[PartialFunction[(Int,Int), String]])\n  (implicit xyplot : XYPlot = figures.figure.plot,\n   mtv : CanViewAsTensor2[M,Int,Int,V]) {\n\n    val mt = mtv(img);\n\n    val series = xyplot.nextSeries;\n\n    val domain = mt.domain;\n    val (minx,maxx) = (domain._2.min, domain._2.max);\n    val (miny,maxy) = (domain._1.min, domain._1.max);\n\n    val items = domain.toIndexedSeq;\n\n    // initialize dataset\n    val dataset = XYZDataset(\n      items = items,\n      name = if (name == null) \"Series \"+series else name,\n      x = (k : (Int,Int)) => k._2 + offset._2,\n      y = (k : (Int,Int)) => k._1 + offset._1,\n      z = (k : (Int,Int)) => mt.scalar.toDouble(mt(k._1, k._2)),\n      label = (k : (Int,Int)) => if (labels != null && labels.isDefinedAt(k)) labels(k) else null,\n      tip = (k : (Int,Int)) => if (tips != null && tips.isDefinedAt(k)) tips(k) else null\n    );\n\n    // initialize renderer\n    import org.jfree.chart.renderer.xy.XYBlockRenderer\n    val renderer = new XYBlockRenderer();\n    renderer.setSeriesPaint(0, XYPlot.paint(series));\n    renderer.setSeriesShape(0, XYPlot.shape(series));\n    renderer.setSeriesStroke(0, XYPlot.stroke(series));\n    renderer.setSeriesFillPaint(0, XYPlot.fillPaint(series));\n    renderer.setSeriesOutlinePaint(0, XYPlot.outlinePaint(series));\n    renderer.setSeriesOutlineStroke(0, XYPlot.outlineStroke(series));\n\n    val tooltipGenerator = new org.jfree.chart.labels.XYToolTipGenerator() {\n      override def generateToolTip(dataset : org.jfree.data.xy.XYDataset, series : Int, item : Int) : String = {\n        dataset.asInstanceOf[XYZDataset[_]].getTip(series, item);\n      }\n    }\n    renderer.setSeriesToolTipGenerator(series, tooltipGenerator);\n\n    val labelGenerator = new org.jfree.chart.labels.XYItemLabelGenerator() {\n      override def generateLabel(dataset : org.jfree.data.xy.XYDataset, series : Int, item : Int) : String = {\n        dataset.asInstanceOf[XYZDataset[_]].getLabel(series, item);\n      }\n    }\n    renderer.setSeriesItemLabelGenerator(series, labelGenerator);\n    renderer.setSeriesItemLabelsVisible(series, labels != null);\n\n    val staticScale = {\n      if (scale == null)\n        GradientPaintScaleFactory[Double]().apply(mt.values.toList.map(mt.scalar.toDouble)).asInstanceOf[GradientPaintScale[Double]]\n      else\n        scale\n    }\n    \n//    val staticScale : StaticPaintScale = scale match {\n//      case static : StaticPaintScale =>\n//        static;\n//\n//      case dynamic : DynamicPaintScale => {\n//        val values = items.view.map(item =>\n//          mt.scalar.toDouble(mt(item._1, item._2))).filter(!_.isNaN);\n//        if (values.isEmpty) {\n//          dynamic(lower = Double.NaN, upper = Double.NaN);\n//        } else {\n//          dynamic(lower = values.min, upper = values.max);\n//        }\n//      }\n//    }\n\n    val paintScale = new org.jfree.chart.renderer.PaintScale {\n      override def getLowerBound = staticScale.lower;\n      override def getUpperBound = staticScale.upper;\n      override def getPaint(value : Double) =\n        staticScale(value);\n    }\n\n    renderer.setPaintScale(paintScale);\n    renderer.setBlockAnchor(org.jfree.ui.RectangleAnchor.BOTTOM_LEFT);\n    renderer.setBlockWidth(1);\n    renderer.setBlockHeight(1);\n\n    xyplot.plot.getRangeAxis.setInverted(true);\n    xyplot.plot.getRangeAxis.setLowerBound(miny+offset._2);\n    xyplot.plot.getRangeAxis.setUpperBound(maxy+1+offset._2);\n    xyplot.plot.getRangeAxis.setStandardTickUnits(XYPlot.integerTickUnits);\n    \n    xyplot.plot.getDomainAxis.setLowerBound(minx+offset._1);\n    xyplot.plot.getDomainAxis.setUpperBound(maxx+1+offset._1);\n    xyplot.plot.getDomainAxis.setStandardTickUnits(XYPlot.integerTickUnits);\n\n    // set legend\n    if (showScale) {\n      val legendAxis = new org.jfree.chart.axis.NumberAxis();\n      legendAxis.setLowerBound(staticScale.lower);\n      legendAxis.setUpperBound(staticScale.upper);\n\n      val legend = new org.jfree.chart.title.PaintScaleLegend(paintScale, legendAxis);\n      import org.jfree.chart.title._;\n      import org.jfree.ui._;\n      import org.jfree.chart.block._;\n      legend.setMargin(new RectangleInsets(40, 2, 40, 2));\n      legend.setPadding(new RectangleInsets(10, 2, 10, 2));\n      legend.setBorder(1,1,1,1);\n      legend.setBackgroundPaint(Color.white);\n      legend.setPosition(RectangleEdge.RIGHT);\n      xyplot.chart.addSubtitle(legend);\n    }\n\n    // add dataset and renderer to plot\n    xyplot.plot.setDataset(series, dataset);\n    xyplot.plot.setRenderer(series, renderer);\n    xyplot.refresh();\n  }\n}\n\n/**\n * An object with access to the Plotting trait members.\n *\n * @author dramage\n */\nobject Plotting extends Plotting {\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/Random.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage library;\n\nimport random.MersenneTwisterFast\n\n/**\n * <p>Random number generation.  This class uses the MersenneTwisterFast\n * implementation by Sean Luke http://www.cs.gmu.edu/~sean/research/\n * as its underlying random number generator.  The Mersenne Twister\n * is very fast with an excellent pseudo-random distribution, but it\n * is not cryptographically strong.</p>\n *\n * <p>Each random number generating method accepts a\n * MersenneTwisterFast implementation as an implicit argument, defaulting\n * to the <code>Random.mt</code> instance.  That instance's seed is set\n * with the long value held in the scalala.library.random.seed System property.\n * If the property is not defined, the current time in milliseconds is used\n * as the random seed.</p>\n *\n * <p>The MersenneTwisterFast implementation is not thread-safe, so all\n * accessors to an instance (<code>mt</code>) wrap calls in a mt.synchronized\n * block.  Therefore, calling a vector constructor is substantially faster\n * than calling rand() many times.</p>\n *\n * <p>The seed can be set with the system property during Java invocation, e.g. by\n * -Dscalala.library.random.seed=1l</p>\n *\n * @author dramage,afwlehmann\n */\nobject Random {\n  /**\n   * Returns a pseudo-random number from [0,1).\n   */\n  def rand()(implicit mt: MersenneTwisterFast): Double = mt.synchronized {\n    mt.nextDouble()\n  }\n\n  /**\n   * Returns a pseudo-random gaussian variable.\n   * */\n  def randn()(implicit mt: MersenneTwisterFast) = mt.synchronized {\n    mt.nextGaussian()\n  }\n\n  /**\n   * Returns a pseudo-random integer between 0 (incl.) and `max` (excl.).\n   */\n  def randi(max: Int)(implicit mt: MersenneTwisterFast) = mt.synchronized {\n    mt.nextInt(max)\n  }\n\n  lazy val seed : Long = {\n    val prop = System.getProperty(\"scalala.library.random.seed\");\n    if (prop != null) prop.toLong else System.currentTimeMillis;\n  }\n\n  implicit val mt : MersenneTwisterFast =\n    new MersenneTwisterFast(seed);\n}\n"
  },
  {
    "path": "src/main/scala/scalala/library/Statistics.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\n\nimport math._\nimport Numerics._\nimport operators.Implicits._\nimport generic.collection.{CanViewAsVector,CanViewAsTensor1}\n\n/**\n * Matlab-like statistical methods.\n *\n * @author dramage,afwlehmann\n */\ntrait Statistics {\n\n  private val sqrt2 = sqrt(2);\n\n  /**\n   * Computes the cumulative density function of the value x.\n   */\n  def normcdf(x: Double, mu : Double = 0.0, sigma : Double = 1.0) =\n    .5 * (1 + erf((x - mu) / sqrt2 / sigma));\n  \n  /**\n   * Computes the Pearson correlation coefficient between two objects that\n   * can be viewed as Tensor1 instances (such as arrays, vectors, counters)\n   * with values that can be viewed as doubles.\n   *\n   * Code adapted excerpted from Wikipedia:\n   *   http://en.wikipedia.org/wiki/Pearson%27s_correlation_coefficient\n   */\n  def corrcoef[K,X,VX,Y,VY](x : X, y : Y)\n  (implicit xvt : CanViewAsTensor1[X,K,VX], yvt : CanViewAsTensor1[Y,K,VY],\n   vx : VX => Double, vy : VY => Double) : Double = {\n    // tensor view of x and y\n    val xt = xvt(x);\n    val yt = yvt(y);\n\n    val N = xt.size;\n    var sum_sq_x = 0.0;\n    var sum_sq_y = 0.0;\n    var sum_coproduct = 0.0;\n    var mean_x = 0.0;\n    var mean_y = 0.0;\n    var i = 0;\n    (xt joinAll yt) { (k : K, xv : VX, yv : VY) =>\n      val sweep = i / (i + 1.0);\n      val delta_x = xv - mean_x;\n      val delta_y = yv - mean_y;\n      sum_sq_x += (delta_x * delta_x * sweep);\n      sum_sq_y += (delta_y * delta_y * sweep);\n      sum_coproduct += (delta_x * delta_y * sweep);\n      i += 1;\n      mean_x += (delta_x / i);\n      mean_y += (delta_y / i);\n    }\n    val pop_sd_x = math.sqrt(sum_sq_x / N);\n    val pop_sd_y = math.sqrt(sum_sq_y / N);\n    val cov_x_y = sum_coproduct / N;\n    return cov_x_y / (pop_sd_x * pop_sd_y);\n  }\n\n  /**\n   * Computes Kendall's Tau correlation coefficient between the two vectors\n   * x and y.  The measure is a correlation based on ranks, essentially counting\n   * the number of concordant minus discordant pairs, normalized by the number\n   * of pairs.  Breaking ties is tricky and important.  See:\n   *\n   *  \"A modification of Kendall's Tau for the case of arbitrary ties in both\n   *   rankings\" by L. M. Adler, 1957.  http://www.jstor.org/stable/2281397?seq=1\n   */\n  def kendall[X,XV,Y,YV](x : X, y : Y)\n  (implicit xvt : CanViewAsVector[X,XV], yvt : CanViewAsVector[Y,YV]) : Double = {\n    val _x = xvt(x); @inline implicit def xvtod(v : XV) = _x.scalar.toDouble(v);\n    val _y = yvt(y); @inline implicit def yvtod(v : YV) = _y.scalar.toDouble(v);\n    require(_x.size == _y.size, \"Vectors must have same length\");\n\n    val N = _x.size;\n    if (N == 0) {\n      return Double.NaN;\n    }\n\n    // keep track of ties in x and in y\n    val xties = new scala.collection.mutable.HashMap[Double,scala.collection.mutable.HashSet[Int]];\n    val yties = new scala.collection.mutable.HashMap[Double,scala.collection.mutable.HashSet[Int]];\n\n    var numer = 0.0;\n    for (i <- 0 until N; j <- 0 until i) {\n      if (_x(i) == _x(j)) {\n        val s = xties.getOrElseUpdate(_x(i), new scala.collection.mutable.HashSet[Int]);\n        s += i;\n        s += j;\n      }\n      if (_y(i) == _y(j)) {\n        val s = yties.getOrElseUpdate(_y(i), new scala.collection.mutable.HashSet[Int]);\n        s += i;\n        s += j;\n      }\n      numer += math.signum(_x(i) - _x(j)) * math.signum(_y(i) - _y(j));\n    }\n\n    var denom = N * (N - 1.0) / 2.0;\n    var xdenom = xties.valuesIterator.map(s => s.size * (s.size - 1.0)).sum / 2.0;\n    var ydenom = yties.valuesIterator.map(s => s.size * (s.size - 1.0)).sum / 2.0;\n\n    return numer / math.sqrt((denom - xdenom) * (denom - ydenom));\n  }\n\n//  def mannwhitneyu(a : Seq[Double], b : Seq[Double]) = {\n//    val merged = (a.map(_ -> 'a') ++ b.map(_ -> 'b')).sortWith(_._1 < _._1);\n//    val ranked = ranks(merged.toArray.map(_._1));\n//    val aU = (for ((v,r) <- (merged.iterator zip ranked.iterator); if v._2 == 'a') yield r).sum - (a.size * (a.size + 1) / 2);\n//    val bU = (for ((v,r) <- (merged.iterator zip ranked.iterator); if v._2 == 'b') yield r).sum - (b.size * (b.size + 1) / 2);\n//    val (bigU,smallU) = if (aU > bU) (aU,bU) else (bU,aU);\n//    val sd = math.sqrt(a.size * b.size * (a.size + b.size + 1) / 12.0);\n//    (aU, normcdf(-abs((bigU - a.size * b.size / 2.0) / sd)));\n//  }\n\n  /** Returns n choose k, how many ways to pick k objects from n. */\n  def nchoosek(n : Int, k : Int) : Long = {\n    var aa = 0.0;\n    var ai = k+1;\n    while (ai <= n) aa += math.log(ai);\n\n    var bb = 0.0;\n    var bi = 2;\n    while (bi <= n-k) bb += math.log(bi);\n\n    math.exp(aa - bb).round;\n  }\n\n  /** Returns n factorial, the number of orderings of n objects. */\n  def factorial(n : Int) : Long = {\n    var i = n;\n    var rv = 1l;\n    while (i > 1) {\n      rv *= i;\n      i -= 1;\n    }\n    rv;\n  }\n\n  /**\n   * Returns the cumulative distribution function of the binomial evaluated\n   * at x; i.e. returns the probability that at most x draws out of n draws\n   * of a binomial with paramater p come up heads.\n   */\n  def binomialCDF(n:Int,p:Double)(x:Int) = {\n    var rv = 0.0;\n    var i = 0;\n    while (i < x) {\n      rv += nchoosek(n,i) * math.pow(p,i) * math.pow(1-p,n-i);\n      i += 1;\n    }\n    rv;\n  }\n\n}\n\n/**\n * An object with access to the Statistics trait members.\n *\n * @author dramage\n */\nobject Statistics extends Statistics { }\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/Storage.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala.library\n\n\nimport scalala.tensor.{::, Matrix}\nimport scalala.tensor.dense.DenseMatrix\nimport java.io._\nimport util.matching.Regex\n\ntrait Storage {\n\n  /**\n   * Deserializes a DenseMatrix from the given input stream.\n   *\n   * @param is\n   *  the input stream\n   * @param skipRows\n   *  number of lines to skip at the beginning\n   * @param columns\n   *  indices of the columns to be used, or null for all columns (default), e.g.\n   *  List(1,3) for columns 2 and 4, respectively\n   * @param delimiter\n   *  a regular expression defining the delimiter that is used to separate the\n   *  values\n   * @param comments\n   *  a regular expression defining the start of comments which will be removed\n   *  throughout the process\n   */\n  def loadtxt(is: InputStream,\n              skipRows: Int = 0,\n              columns: Seq[Int] = null,\n              delimiter: Regex = Storage.defaultDelimiter,\n              comments: Regex = Storage.defaultComments):\n    DenseMatrix[Double] =\n  {\n    require(skipRows >= 0)\n    require(columns == null || columns.size > 0)\n\n    val it = new Iterator[Array[String]] {\n      val br = new BufferedReader(new InputStreamReader(is))\n      def hasNext = br.ready\n      def next =\n        // Regex.split actually returns an Array(\"\") in case of an empty\n        // input string yet we want Array.empty instead, thus:\n        delimiter split (comments replaceFirstIn (br.readLine, \"\") trim) match {\n          case Array(\"\") => Array.empty[String]\n          case r => r\n        }\n    }\n\n    for (i <- 0 until skipRows if it.hasNext) { it.next() }\n\n    var numCols = -1\n    val rows: Array[Array[Double]] =\n      (for (tokens <- it if !tokens.isEmpty) yield {\n        if (tokens.size != numCols) {\n          if (numCols == -1)\n            numCols = tokens.size\n          else\n            throw new RuntimeException(\"All lines must have the same number of columns!\")\n        }\n        if (columns == null)\n          tokens.map(_.toDouble).toArray[Double]\n        else\n          ((for (colIdx <- columns) yield\n            tokens(colIdx).toDouble)).toArray[Double]\n      }).toArray\n\n    if (rows.size > 0)\n      DenseMatrix(rows:_*)\n    else\n      null\n  }\n\n\n  /**\n   * Serializes the given matrix to the given output stream. The given delimiter\n   * is used to separate the values of each row.\n   */\n  def storetxt(os: OutputStream, m: Matrix[Double], delimiter: String = \"\\t\") {\n    val bw = new BufferedWriter(new OutputStreamWriter(os))\n    for (i <- 0 until m.numRows) {\n      bw.write(m(i,::).values.iterator map (\"%.15e\".format(_)) mkString delimiter)\n      bw.newLine()\n    }\n    bw.flush()\n  }\n\n\n}\n\nobject Storage extends Storage {\n\n  val defaultDelimiter: Regex = \"\"\"\\s+\"\"\".r\n  val defaultComments: Regex = \"\"\"#.*$\"\"\".r\n\n}\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/Dataset.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport scala.collection.mutable.ArrayBuffer;\n\n/**\n * An XY dataset consisting of some number of named series, each consisting\n * of items of type Item, with an associated x value, y value, and optionally\n * a name and tooltip.\n * \n * @author dramage\n */\nclass XYDataset[Item](x : Item=>Number, y : Item=>Number, label : Item=>String, tip : Item=>String)\nextends org.jfree.data.xy.AbstractXYDataset {\n  val names = ArrayBuffer[String]();\n  val items = ArrayBuffer[IndexedSeq[Item]]();\n\n  override def getSeriesKey(series : Int) =\n    names(series);\n\n  override def getSeriesCount =\n    names.length;\n\n  override def getItemCount(series : Int) =\n    items(series).length;\n\n  override def getX(series : Int, item : Int) : Number =\n    x(items(series)(item));\n\n  override def getY(series : Int, item : Int) : Number =\n    y(items(series)(item));\n\n  def getLabel(series : Int, item : Int) : String =\n    label(items(series)(item));\n\n  def getTip(series : Int, item : Int) : String =\n    tip(items(series)(item));\n}\n\nobject XYDataset {\n  def apply[Item](name : String, items : IndexedSeq[Item], x : Item=>Number, y : Item=>Number, label : Item=>String, tip : Item=>String)\n  : XYDataset[Item] = {\n    val rv = new XYDataset(x, y, label, tip);\n    rv.names += name;\n    rv.items += items;\n    rv;\n  }\n}\n\n/**\n * An XYX dataset consisting of some number of named series, each consisting\n * of items of type Item, with an associated x value, y value, z value,\n * and optionally a name and tooltip.\n *\n * @author dramage\n */\nclass XYZDataset[Item](x : Item=>Number, y : Item=>Number, z : Item=>Number, label : Item=>String, tip : Item=>String)\nextends org.jfree.data.xy.AbstractXYZDataset {\n  val names = ArrayBuffer[String]();\n  val items = ArrayBuffer[IndexedSeq[Item]]();\n\n  override def getSeriesKey(series : Int) =\n    names(series);\n\n  override def getSeriesCount =\n    names.length;\n\n  override def getItemCount(series : Int) =\n    items(series).length;\n\n  override def getX(series : Int, item : Int) : Number =\n    x(items(series)(item));\n\n  override def getY(series : Int, item : Int) : Number =\n    y(items(series)(item));\n\n  override def getZ(series : Int, item : Int) : Number =\n    z(items(series)(item));\n\n  def getLabel(series : Int, item : Int) : String =\n    label(items(series)(item));\n\n  def getTip(series : Int, item : Int) : String =\n    tip(items(series)(item));\n}\n\nobject XYZDataset {\n  def apply[Item](name : String, items : IndexedSeq[Item], x : Item=>Number, y : Item=>Number, z : Item=>Number, label : Item=>String, tip : Item=>String)\n  : XYZDataset[Item] = {\n    val rv = new XYZDataset(x, y, z, label, tip);\n    rv.names += name;\n    rv.items += items;\n    rv;\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/ExportGraphics.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport java.io.{File,OutputStream,FileOutputStream,IOException};\nimport java.awt.Graphics2D;\n\n/**\n * Utility functions for exporting a Graphics2D drawable to some eps, pdf,\n * and png.\n *\n * @author dramage, Robby McKilliam\n */\nobject ExportGraphics {\n  /** A Drawable is any function that draws to a Graphics2D context. */\n  type Drawable = ((Graphics2D)=>Unit);\n\n  /**\n   * Writes the given drawable to a new file of the given name with\n   * the given dpi (for rasterized formats only).  The extension of the file\n   * determines its format, with options png, eps, svg, and pdf.\n   */\n  def writeFile(file : File, draw : Drawable, width : Int, height : Int, dpi : Int = 72) = {\n    lazy val fos = new FileOutputStream(file);\n    if (file.getName.toLowerCase.endsWith(\".png\")) {\n      try {\n        writePNG(fos,draw,width,height,dpi);\n      } finally {\n        fos.close();\n      }\n    } else if (file.getName.toLowerCase.endsWith(\".eps\")) {\n      try {\n        writeEPS(fos,draw,width,height);\n      } finally {\n        fos.close();\n      }\n    } else if (file.getName.toLowerCase.endsWith(\".pdf\")) {\n      try {\n        writePDF(fos,draw,width,height);\n      } finally {\n        fos.close();\n      }\n//    } else if (file.getName.toLowerCase.endsWith(\".svg\")) {\n//      try {\n//        writeSVG(fos,draw,width,height);\n//      } finally {\n//        fos.close();\n//      }\n    } else {\n      throw new IOException(\"Unrecognized file extension: should be png, svg, eps, or pdf\");\n    }\n  }\n\n  /** \n   * Writes the given drawable to the given OutputStream at the given dpi,\n   * formatted as png.\n   */\n  def writePNG(out : OutputStream, draw : Drawable, width : Int, height : Int, dpi : Int = 72) {\n    import javax.imageio.ImageIO;\n    import java.awt.image.BufferedImage;\n    \n    // default dpi is 72\n    val scale = dpi / 72.0;\n    val swidth = (width * scale).toInt;\n    val sheight = (height * scale).toInt;\n\n    val image = new BufferedImage(swidth,sheight,BufferedImage.TYPE_INT_ARGB);\n    val g2d = image.createGraphics();\n    g2d.scale(scale, scale);\n    draw(g2d);\n    g2d.dispose;\n\n    ImageIO.write(image, \"png\", out);\n  }\n\n  /**\n   * Writes the given drawable to the given OutputStream formatted as eps.\n   */\n  def writeEPS(out : OutputStream, draw : Drawable, width : Int, height : Int) {\n    import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;\n    import org.apache.xmlgraphics.java2d.GraphicContext;\n\n    val g2d = new EPSDocumentGraphics2D(false);\n    g2d.setGraphicContext(new GraphicContext);\n    g2d.setupDocument(out, width, height);\n    draw(g2d);\n    g2d.finish();\n  }\n\n  /**\n   * Writes the given drawable to the given OutputStream formatted as pdf.\n   * Contributed by Robby McKilliam.\n   */\n  def writePDF(out : OutputStream, draw : Drawable, width : Int, height : Int) {\n    import com.lowagie.text.Document;\n    import com.lowagie.text.Rectangle;\n    import com.lowagie.text.pdf.PdfWriter;\n  \n    val document = new Document();\n\n    try {\n      document.setPageSize(new Rectangle(width, height));\n      val writer = PdfWriter.getInstance(document, out);\n      document.open();\n\n      val cb = writer.getDirectContent();\n      val tp = cb.createTemplate(width, height);\n      val g2d = tp.createGraphics(width, height);\n\n      draw(g2d);\n\n      g2d.dispose;\n\n      cb.addTemplate(tp, 1, 0, 0, 1, 0, 0);\n    } finally {\n      document.close();\n    }\n  }\n  \n//  /**\n//   * Writes the given drawable to the given OutputStream formatted as svg.\n//   */\n//  def writeSVG(out : OutputStream, draw : Drawable, width : Int, height : Int) {\n//    import org.apache.batik.svggen.SVGGraphics2D;\n//    import org.apache.batik.dom.GenericDOMImplementation;\n//    import org.w3c.dom.Document;\n//    import java.io.OutputStreamWriter;\n//    \n//    val dom = GenericDOMImplementation.getDOMImplementation();\n//    val document = dom.createDocument(\"http://www.w3.org/2000/svg\",\"svg\",null);\n//    val g2d = new SVGGraphics2D(document);\n//    draw(g2d);\n//    g2d.stream(new OutputStreamWriter(out, \"UTF-8\"), true);\n//    g2d.dispose();\n//  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/Figure.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport scala.collection.mutable.ArrayBuffer;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\nimport java.awt.Graphics2D;\nimport javax.swing.WindowConstants;\n\n/** A Figure holds a collection of XYPlot instances */\nclass Figure(figures : Figures) {\n  /** List of plots in the figure. */\n  protected val plots = ArrayBuffer[Option[XYPlot]]();\n\n  /** How many rows of plots are in the figure */\n  private var rows_ = 1;\n  def rows = rows_;\n  def rows_=(newrows : Int) : Unit = {\n    rows_ = newrows;\n    refresh();\n  }\n\n  /** How many cols of plots are in the figure */\n  private var cols_ = 1 ;\n  def cols = cols_;\n  def cols_=(newcols : Int) : Unit = {\n    cols_ = newcols;\n    refresh();\n  }\n\n  /** Visibility state of the plot */\n  private var visible_ = true;\n  def visible = visible_;\n  def visible_=(newvis : Boolean) : Unit = {\n    visible_ = newvis;\n    frame.setVisible(visible_);\n  }\n\n  /** JPanel holding for drawing subplots in this figure. */\n  val contents = {\n    val _c = new JPanel();\n    _c.setSize(600,400);\n    _c;\n  }\n\n  /** The Swing frame for this plot */\n  lazy val frame : JFrame = {\n    val f = new JFrame(\"Figure \"+(figures.number(this)));\n    f.setSize(600,400);\n    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\n    f.setLayout(new java.awt.BorderLayout());\n    f.add(contents, java.awt.BorderLayout.CENTER);\n\n    // we use visible_ to avoid an infinite loop\n    f.setVisible(visible_);\n\n    f\n  }\n\n  /** Returns the number of the given plot in this container */\n  def number(plot : XYPlot) : Int =\n    plots.indexOf(plot);\n\n  private var plot_ = 0;\n  /** Returns the current plot in the figure */\n  def plot : XYPlot = plots(plot_).get;\n\n  /** Uses the given plot number. */\n  def plot_=(number : Int) : Unit = {\n    assert(number >= 0, \"Plot number must be non-negative\");\n    while (plots.length <= number) {\n      plots += None;\n    }\n    if (plots(number) == None) {\n      plots(number) = Some(new XYPlot(this));\n    }\n    plot_ = number;\n  }\n\n  // create the initial plot (don't call clear lest we pop up a window)\n  plot = 0;\n\n  /** Clears the current plot */\n  def clear() {\n    contents.removeAll();\n    plots.clear();\n    plot = 0;\n    rows = 1;\n    cols = 1;\n    refresh();\n  }\n\n  /** Redraws the figure */\n  def refresh() : Unit = {\n    while (plots.length < rows * cols) {\n      plots += None;\n    }\n    while (plots.length > rows * cols) {\n      plots.remove(plots.length-1);\n    }\n\n    contents.removeAll;\n    contents.setLayout(new java.awt.GridLayout(rows,cols));\n    for (plot <- plots) {\n      contents.add(plot match { case Some(plot) => plot.panel; case None => new JPanel() });\n    }\n\n    frame.repaint();\n    frame.setVisible(visible);\n  }\n\n  def drawPlots(g2d : Graphics2D) {\n    val plotWidth  = contents.getWidth / cols;\n    val plotHeight = contents.getHeight / rows;\n    var px = 0; var py = 0;\n    for (opt <- plots) {\n      opt match {\n        case Some(plot) =>\n          plot.chart.draw(g2d, new java.awt.Rectangle(px*plotWidth, py*plotHeight, plotWidth, plotHeight));\n        case None => {}\n      }\n      px = (px +1)%cols;\n      if(px == 0) py = (py + 1)%rows;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/Figures.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport scala.collection.mutable.ArrayBuffer;\n\n/** Class that holds a collection of Figure instances */\nclass Figures {\n  private val figures = ArrayBuffer[Option[Figure]]();\n\n  /** Returns the number of the given figure */\n  def number(figure : Figure) : Int = figures.indexOf(Some(figure));\n\n  /** Returns the current figure.  Defaults to 1, but allows 0. */\n  var figure_ : Int = 1;\n  def figure : Figure = figures(figure_).get;\n  def figure_=(number : Int) : Unit = {\n    while (figures.length <= number) {\n      figures += None;\n    }\n    if (figures(number) == None) {\n      figures(number) = Some(new Figure(this));\n    }\n    figure_ = number;\n  }\n\n  /** Returns the current figure's current plot */\n  def plot : XYPlot = figure.plot;\n\n  // Set the current figure to figure 1\n  figure = 1;\n}\n\nobject Figures {\n  lazy val global = new Figures();\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/HistogramBins.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport scalala.generic.collection.CanViewAsTensor1;\n\n/**\n * Bins for a histogram.  These can be implicitly constructed from:\n * <pre>\n *   x : HistogramBins = 10  // 10 dynamically determined histogram bins\n *   x : HistogramBins = Array(1.0,2.0,3.2) // five buckets wit the given splits\n *   x : HistogramBins = (0,100,10) // ten bins evenly dividing 0 to 100.\n * </pre>\n *\n * @author dramage\n */\nsealed trait HistogramBins;\n\n/**\n * Set of histograms for binning data using the given splits.\n *\n * @author dramage\n */\ncase class StaticHistogramBins(splits : Array[Double])\nextends HistogramBins {\n  /** Returns the bin for the given value, between 0 and splits.length inclusive. */\n  def bin(value : Double) = {\n    var i = 0;\n    while (i < splits.length && value > splits(i)) {\n      i += 1;\n    }\n    i;\n  }\n}\n\n/**\n * Create a set of StaticHistogramBins from a number and an (eventual)\n * lower and upper bound.\n *\n * @author dramage\n */\ncase class DynamicHistogramBins(number : Int = 10)\nextends HistogramBins {\n  def apply(lower : Double, upper : Double) =\n    StaticHistogramBins(Array.tabulate(number-1)(i => lower + ((i + 1.0) / (number)) * (upper - lower)));\n}\n\n/**\n * Static constructors for HistogramBins.\n *\n * @author dramage\n */\nobject HistogramBins {\n  implicit def fromNumber(number : Int) : HistogramBins =\n    DynamicHistogramBins(number);\n\n//  implicit def fromSplits[S,K,V](splits : S)(implicit tt : CanViewAsTensor1[S,K,V], v : V=>Double) : HistogramBins =\n//    StaticHistogramBins(t.domain(splits).map(d => v(t.get(splits, d))).toArray);\n\n  implicit def fromRange(minMaxCount : (Double,Double,Int)) : HistogramBins =\n    DynamicHistogramBins(minMaxCount._3)(minMaxCount._1, minMaxCount._2);\n}\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/PaintScale.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport java.awt.{Color,Paint,TexturePaint};\nimport java.awt.geom.Rectangle2D;\nimport java.awt.image.BufferedImage;\n\n/**\n * Maps items of type T to a well defined Paint (usually a color).\n *\n * An implicit conversion exists to make a singleton PaintScaleFactory from\n * a PaintScale instance, which means that PaintScales can be provided\n * directly whenever a PaintScaleFactory is required.\n *\n * @author dramage\n */\nsealed trait PaintScale[T] extends (T => Paint);\n\n/**\n * A simple numeric paint scale for mapping a number within a range to a\n * corresponding element of a pre-computed color gradient.  Colors from the\n * given gradient array are used linearly to represent values between\n * lower and upper.\n *\n * @author dramage\n */\ncase class GradientPaintScale[T]\n(lower : T, upper : T, gradient : Array[Color] = PaintScale.WhiteToBlack)\n(implicit view : T=>Double)\nextends PaintScale[T] {\n  def apply(value : T) : Paint = {\n    if (view(value).isNaN) {\n      PaintScale.nanPaint\n    } else {\n      val index = gradient.length * (value - lower) / (upper - lower);\n      gradient(math.min(gradient.length-1, math.max(0, index.toInt)));\n    }\n  }\n}\n\n/**\n * Maps items to colors using the given partial function.  If no color\n * is provided for the given item, then returns PaintScale.nanPaint.\n *\n * @author dramage\n */\ncase class CategoricalPaintScale[T]\n(categories : PartialFunction[T,Paint])\nextends PaintScale[T] {\n  def apply(value : T) : Paint = {\n    if (!categories.isDefinedAt(value)) {\n      PaintScale.nanPaint\n    } else {\n      categories(value)\n    }\n  }\n}\n\nobject PaintScale {\n\n  /**\n   * Convert a color description string into a color suitable for plotting.\n   * @param colorcode A string that is a single character (like \"k\"), a name\n   * (like \"black\"), \"r,g,b\" or, \"[r,g,b]\"\n   *\n   * @author Patryk Laurent\n   */\n  def convertToColor(colorcode:String) : java.awt.Color = {\n      val rgbcsv =  \"(.*),(.*),(.*)\".r;\n      colorcode.toLowerCase.replace(\" \", \"\").replace(\"[\",\"\").replace(\"]\", \"\") match {\n          case \"y\" | \"yellow\"  => yellow\n          case \"m\" | \"magenta\" => magenta\n          case \"c\" | \"cyan\"    => cyan\n          case \"r\" | \"red\"     => red\n          case \"g\" | \"green\"   => green\n          case \"b\" | \"blue\"    => blue\n          case \"w\" | \"white\"   => white\n          case \"k\" | \"black\"   => black\n          case rgbcsv(r,g,b)   => new java.awt.Color(r.toInt,g.toInt,b.toInt)\n          case uninterpretable:String => throw new IllegalArgumentException(\n            \"Expected color code to be either y m c r g b w k OR R,G,B or \" +\n            \"[R,G,B] where R,G,B are numbers such that 0<=R,G,B<=255, but got '\" +\n            uninterpretable + \"' instead.\")\n      }\n  }\n\n  /** Creates a GradientPaintScale automatically for the given range. */\n  implicit def gradientTuple[T](vLowerUpper : (T,T))(implicit view : T=>Double)\n  : GradientPaintScale[T] =\n    GradientPaintScale[T](vLowerUpper._1, vLowerUpper._2);\n\n  /** Creates a CategoricalPaintScale from the provided partial function. */\n  implicit def literalColorMap[T](map : PartialFunction[T,Paint])\n  : CategoricalPaintScale[T] =\n    CategoricalPaintScale[T](map);\n\n\n  //\n  // Default colors and patterns.\n  //\n\n  /** For painting NaN. */\n  val nanPaint = {\n    val img = new BufferedImage(5,5,BufferedImage.TYPE_INT_ARGB);\n    \n    val gfx = img.getGraphics;\n    gfx.setColor(Color.gray);\n    gfx.drawLine(0,0,4,4);\n    gfx.dispose();\n    \n    new TexturePaint(img, new Rectangle2D.Double(0,0,5,5));\n  }\n\n  /** The Category10 palette from Protovis http://vis.stanford.edu/protovis/docs/color.html */\n  object Category10 {\n    val values : Array[Color] = Array(\n      \"#1f77b4\", \"#ff7f0e\", \"#2ca02c\", \"#d62728\", \"#9467bd\",\n      \"#8c564b\", \"#e377c2\", \"#7f7f7f\", \"#bcbd22\", \"#17becf\"\n    ).map(Color.decode);\n    \n    val blue = values(0);\n    val orange = values(1);\n    val green = values(2);\n    val red = values(3);\n    val purple = values(4);\n    val brown = values(5);\n    val magenta = values(6);\n    val gray = values(7);\n    val gold = values(8);\n    val teal = values(9);\n    \n    def apply(i : Int) = values(i);\n  }\n  \n  /** The Category20 palette from Protovis http://vis.stanford.edu/protovis/docs/color.html */\n  object Category20 {\n    val values : Array[Color] = Category10.values ++ Array(\n      \"#aec7e8\", \"#ffbb78\", \"#98df8a\", \"#ff9896\", \"#c5b0d5\",\n      \"#c49c94\", \"#f7b6d2\", \"#c7c7c7\", \"#dbdb8d\", \"#9edae5\"\n    ).map(Color.decode);\n    \n    val lightblue = values(10);\n    val lightorange = values(11);\n    val lightgreen = values(12);\n    val lightred = values(13);\n    val lightpurple = values(14);\n    val lightbrown = values(15);\n    val lightmagenta = values(16);\n    val lightgray = values(17);\n    val lightgold = values(18);\n    val lightteal = values(19);\n    \n    def apply(i : Int) = values(i);\n  }\n\n  //\n  // A large pallete of color literals from ProtoVis\n  //\n  val aliceblue = Color.decode( \"#f0f8ff\");\n  val antiquewhite = Color.decode( \"#faebd7\");\n  val aqua = Color.decode( \"#00ffff\");\n  val aquamarine = Color.decode( \"#7fffd4\");\n  val azure = Color.decode( \"#f0ffff\");\n  val beige = Color.decode( \"#f5f5dc\");\n  val bisque = Color.decode( \"#ffe4c4\");\n  val black = Color.decode( \"#000000\");\n  val blanchedalmond = Color.decode( \"#ffebcd\");\n  val blue = Color.decode( \"#0000ff\");\n  val blueviolet = Color.decode( \"#8a2be2\");\n  val brown = Color.decode( \"#a52a2a\");\n  val burlywood = Color.decode( \"#deb887\");\n  val cadetblue = Color.decode( \"#5f9ea0\");\n  val chartreuse = Color.decode( \"#7fff00\");\n  val chocolate = Color.decode( \"#d2691e\");\n  val coral = Color.decode( \"#ff7f50\");\n  val cornflowerblue = Color.decode( \"#6495ed\");\n  val cornsilk = Color.decode( \"#fff8dc\");\n  val crimson = Color.decode( \"#dc143c\");\n  val cyan = Color.decode( \"#00ffff\");\n  val darkblue = Color.decode( \"#00008b\");\n  val darkcyan = Color.decode( \"#008b8b\");\n  val darkgoldenrod = Color.decode( \"#b8860b\");\n  val darkgray = Color.decode( \"#a9a9a9\");\n  val darkgreen = Color.decode( \"#006400\");\n  val darkgrey = Color.decode( \"#a9a9a9\");\n  val darkkhaki = Color.decode( \"#bdb76b\");\n  val darkmagenta = Color.decode( \"#8b008b\");\n  val darkolivegreen = Color.decode( \"#556b2f\");\n  val darkorange = Color.decode( \"#ff8c00\");\n  val darkorchid = Color.decode( \"#9932cc\");\n  val darkred = Color.decode( \"#8b0000\");\n  val darksalmon = Color.decode( \"#e9967a\");\n  val darkseagreen = Color.decode( \"#8fbc8f\");\n  val darkslateblue = Color.decode( \"#483d8b\");\n  val darkslategray = Color.decode( \"#2f4f4f\");\n  val darkslategrey = Color.decode( \"#2f4f4f\");\n  val darkturquoise = Color.decode( \"#00ced1\");\n  val darkviolet = Color.decode( \"#9400d3\");\n  val deeppink = Color.decode( \"#ff1493\");\n  val deepskyblue = Color.decode( \"#00bfff\");\n  val dimgray = Color.decode( \"#696969\");\n  val dimgrey = Color.decode( \"#696969\");\n  val dodgerblue = Color.decode( \"#1e90ff\");\n  val firebrick = Color.decode( \"#b22222\");\n  val floralwhite = Color.decode( \"#fffaf0\");\n  val forestgreen = Color.decode( \"#228b22\");\n  val fuchsia = Color.decode( \"#ff00ff\");\n  val gainsboro = Color.decode( \"#dcdcdc\");\n  val ghostwhite = Color.decode( \"#f8f8ff\");\n  val gold = Color.decode( \"#ffd700\");\n  val goldenrod = Color.decode( \"#daa520\");\n  val gray = Color.decode( \"#808080\");\n  val green = Color.decode( \"#008000\");\n  val greenyellow = Color.decode( \"#adff2f\");\n  val grey = Color.decode( \"#808080\");\n  val honeydew = Color.decode( \"#f0fff0\");\n  val hotpink = Color.decode( \"#ff69b4\");\n  val indianred = Color.decode( \"#cd5c5c\");\n  val indigo = Color.decode( \"#4b0082\");\n  val ivory = Color.decode( \"#fffff0\");\n  val khaki = Color.decode( \"#f0e68c\");\n  val lavender = Color.decode( \"#e6e6fa\");\n  val lavenderblush = Color.decode( \"#fff0f5\");\n  val lawngreen = Color.decode( \"#7cfc00\");\n  val lemonchiffon = Color.decode( \"#fffacd\");\n  val lightblue = Color.decode( \"#add8e6\");\n  val lightcoral = Color.decode( \"#f08080\");\n  val lightcyan = Color.decode( \"#e0ffff\");\n  val lightgoldenrodyellow = Color.decode( \"#fafad2\");\n  val lightgray = Color.decode( \"#d3d3d3\");\n  val lightgreen = Color.decode( \"#90ee90\");\n  val lightgrey = Color.decode( \"#d3d3d3\");\n  val lightpink = Color.decode( \"#ffb6c1\");\n  val lightsalmon = Color.decode( \"#ffa07a\");\n  val lightseagreen = Color.decode( \"#20b2aa\");\n  val lightskyblue = Color.decode( \"#87cefa\");\n  val lightslategray = Color.decode( \"#778899\");\n  val lightslategrey = Color.decode( \"#778899\");\n  val lightsteelblue = Color.decode( \"#b0c4de\");\n  val lightyellow = Color.decode( \"#ffffe0\");\n  val lime = Color.decode( \"#00ff00\");\n  val limegreen = Color.decode( \"#32cd32\");\n  val linen = Color.decode( \"#faf0e6\");\n  val magenta = Color.decode( \"#ff00ff\");\n  val maroon = Color.decode( \"#800000\");\n  val mediumaquamarine = Color.decode( \"#66cdaa\");\n  val mediumblue = Color.decode( \"#0000cd\");\n  val mediumorchid = Color.decode( \"#ba55d3\");\n  val mediumpurple = Color.decode( \"#9370db\");\n  val mediumseagreen = Color.decode( \"#3cb371\");\n  val mediumslateblue = Color.decode( \"#7b68ee\");\n  val mediumspringgreen = Color.decode( \"#00fa9a\");\n  val mediumturquoise = Color.decode( \"#48d1cc\");\n  val mediumvioletred = Color.decode( \"#c71585\");\n  val midnightblue = Color.decode( \"#191970\");\n  val mintcream = Color.decode( \"#f5fffa\");\n  val mistyrose = Color.decode( \"#ffe4e1\");\n  val moccasin = Color.decode( \"#ffe4b5\");\n  val navajowhite = Color.decode( \"#ffdead\");\n  val navy = Color.decode( \"#000080\");\n  val oldlace = Color.decode( \"#fdf5e6\");\n  val olive = Color.decode( \"#808000\");\n  val olivedrab = Color.decode( \"#6b8e23\");\n  val orange = Color.decode( \"#ffa500\");\n  val orangered = Color.decode( \"#ff4500\");\n  val orchid = Color.decode( \"#da70d6\");\n  val palegoldenrod = Color.decode( \"#eee8aa\");\n  val palegreen = Color.decode( \"#98fb98\");\n  val paleturquoise = Color.decode( \"#afeeee\");\n  val palevioletred = Color.decode( \"#db7093\");\n  val papayawhip = Color.decode( \"#ffefd5\");\n  val peachpuff = Color.decode( \"#ffdab9\");\n  val peru = Color.decode( \"#cd853f\");\n  val pink = Color.decode( \"#ffc0cb\");\n  val plum = Color.decode( \"#dda0dd\");\n  val powderblue = Color.decode( \"#b0e0e6\");\n  val purple = Color.decode( \"#800080\");\n  val red = Color.decode( \"#ff0000\");\n  val rosybrown = Color.decode( \"#bc8f8f\");\n  val royalblue = Color.decode( \"#4169e1\");\n  val saddlebrown = Color.decode( \"#8b4513\");\n  val salmon = Color.decode( \"#fa8072\");\n  val sandybrown = Color.decode( \"#f4a460\");\n  val seagreen = Color.decode( \"#2e8b57\");\n  val seashell = Color.decode( \"#fff5ee\");\n  val sienna = Color.decode( \"#a0522d\");\n  val silver = Color.decode( \"#c0c0c0\");\n  val skyblue = Color.decode( \"#87ceeb\");\n  val slateblue = Color.decode( \"#6a5acd\");\n  val slategray = Color.decode( \"#708090\");\n  val slategrey = Color.decode( \"#708090\");\n  val snow = Color.decode( \"#fffafa\");\n  val springgreen = Color.decode( \"#00ff7f\");\n  val steelblue = Color.decode( \"#4682b4\");\n  val tan = Color.decode( \"#d2b48c\");\n  val teal = Color.decode( \"#008080\");\n  val thistle = Color.decode( \"#d8bfd8\");\n  val tomato = Color.decode( \"#ff6347\");\n  val turquoise = Color.decode( \"#40e0d0\");\n  val violet = Color.decode( \"#ee82ee\");\n  val wheat = Color.decode( \"#f5deb3\");\n  val white = Color.decode( \"#ffffff\");\n  val whitesmoke = Color.decode( \"#f5f5f5\");\n  val yellow = Color.decode( \"#ffff00\");\n  val yellowgreen = Color.decode( \"#9acd32\");\n  val transparent = new Color(0,0,0,0);\n  \n\n  /** Produces a gradient using the University of Minnesota's school colors, from maroon (low) to gold (high) */\n  lazy val MaroonToGold = createGradient(new Color(0xA0, 0x00, 0x00), new Color(0xFF, 0xFF, 0x00), 256);\n\n  /** Produces a gradient from blue (low) to red (high) */\n  lazy val BlueToRed= createGradient(Color.BLUE, Color.RED, 500);\n\n  /** Produces a gradient from black (low) to white (high) */\n  lazy val BlackToWhite = createGradient(Color.BLACK, Color.WHITE, 500);\n\n  /** Produces a gradient from white (low) to black (high) */\n  lazy val WhiteToBlack = createGradient(Color.WHITE, Color.BLACK, 500);\n\n  /** Produces a gradient from red (low) to green (high) */\n  lazy val RedToGreen = createGradient(Color.RED, Color.GREEN, 500);\n\n  /** Produces a gradient through green, yellow, orange, red */\n  lazy val GreenYelloOrangeRed = createMultiGradient(\n    Array(Color.green, Color.yellow, Color.orange, Color.red), 500);\n\n  /** Produces a gradient through the rainbow: violet, blue, green, yellow, orange, red */\n  lazy val Rainbow = createMultiGradient(\n    Array(new Color(181, 32, 255), Color.blue, Color.green, Color.yellow, Color.orange, Color.red), 500);\n\n  /** Produces a gradient for hot things (black, red, orange, yellow, white) */\n  lazy val Hot = createMultiGradient(\n    Array(Color.black, new Color(87, 0, 0), Color.red, Color.orange, Color.yellow, Color.white), 500);\n\n  /** Produces a different gradient for hot things (black, brown, orange, white) */\n  lazy val Heat = createMultiGradient(\n    Array(Color.black, new Color(105, 0, 0), new Color(192, 23, 0), new Color(255, 150, 38), Color.white), 500);\n\n  /** Produces a gradient through red, orange, yellow */\n  lazy val RedOrangeYellow = createMultiGradient(\n    Array(Color.red, Color.orange, Color.yellow), 500);\n\n  /**\n   * Creates an array of Color objects for use as a gradient, using a linear\n   * interpolation between the two specified colors.\n   *\n   * From http://www.mbeckler.org/heatMap/heatMap.html\n   *\n   * @param one Color used for the bottom of the gradient\n   * @param two Color used for the top of the gradient\n   * @param numSteps The number of steps in the gradient. 250 is a good number.\n   */\n  def createGradient(one : Color, two : Color, numSteps : Int) : Array[Color] = {\n    val r1 = one.getRed();\n    val g1 = one.getGreen();\n    val b1 = one.getBlue();\n\n    val r2 = two.getRed();\n    val g2 = two.getGreen();\n    val b2 = two.getBlue();\n\n    val gradient = new Array[Color](numSteps);\n    var iNorm : Double = 0;\n    for (i <- 0 until numSteps) {\n      iNorm = i / numSteps.toDouble; //a normalized [0:1] variable\n      val newR = (r1 + iNorm * (r2 - r1)).toInt;\n      val newG = (g1 + iNorm * (g2 - g1)).toInt;\n      val newB = (b1 + iNorm * (b2 - b1)).toInt;\n      gradient(i) = new Color(newR, newG, newB);\n    }\n\n    return gradient;\n  }\n\n  /**\n   * Creates an array of Color objects for use as a gradient, using an array\n   * of Color objects. It uses a linear interpolation between each pair of\n   * points.\n   *\n   * From http://www.mbeckler.org/heatMap/heatMap.html\n   *\n   * @param colors An array of Color objects used for the gradient. The\n   *   Color at index 0 will be the lowest color.\n   *\n   * @param numSteps The number of steps in the gradient. 250 is a good number.\n   */\n  def createMultiGradient(colors : Array[Color], numSteps : Int) : Array[Color] = {\n    //we assume a linear gradient, with equal spacing between colors\n    //The final gradient will be made up of n 'sections', where n = colors.length - 1\n    val numSections = colors.length - 1;\n    var gradientIndex = 0; //points to the next open spot in the final gradient\n    val gradient = new Array[Color](numSteps)\n\n    require(numSections > 0, \"Array must have at least two colors\");\n\n    for (section <- 0 until numSections) {\n      //we divide the gradient into (n - 1) sections, and do a regular gradient for each\n      val temp = createGradient(colors(section), colors(section+1), numSteps / numSections);\n      for (i <- 0 until temp.length) {\n        //copy the sub-gradient into the overall gradient\n        gradient(gradientIndex) = temp(i);\n        gradientIndex += 1\n      }\n    }\n\n    if (gradientIndex < numSteps) {\n      //The rounding didn't work out in our favor, and there is at least\n      // one unfilled slot in the gradient[] array.\n      //We can just copy the final color there\n      while (gradientIndex < numSteps) {\n        gradient(gradientIndex) = colors(colors.length - 1);\n        gradientIndex += 1\n      }\n    }\n\n    return gradient;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/PaintScaleFactory.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport java.awt.{Color,Paint,TexturePaint};\nimport java.awt.geom.Rectangle2D;\nimport java.awt.image.BufferedImage;\n\n/**\n * Constructs a PaintScale for the given type T by examining a set of its\n * values.\n *\n * @author dramage\n */\ntrait PaintScaleFactory[T] extends (Traversable[T] => PaintScale[T]);\n\n/**\n * Creates a GradientPaintScale from the min and max of a set of data points.\n * bound are supplied.\n *\n * @author dramage\n */\ncase class GradientPaintScaleFactory[T]\n(gradient : Array[Color] = PaintScale.WhiteToBlack)\n(implicit view : T=>Double)\nextends PaintScaleFactory[T] {\n  override def apply(items : Traversable[T]) : PaintScale[T] = {\n    var min = items.head;\n    var max = items.head;\n    for (item <- items) {\n      if (!view(item).isNaN) {\n        if (item < min) min = item;\n        if (item > max) max = item;\n      }\n    }\n    GradientPaintScale(min, max, gradient);\n  }\n}\n\n/**\n * Creates a categorical paint scale using the Category20 palette borrowed from\n * Protovis. http://vis.stanford.edu/protovis/docs/color.html\n *\n * Beware that category colors can be reused if the number of distinct items\n * is greater than 20.\n *\n * @author dramage\n */\ncase class CategoricalPaintScaleFactory[T]() extends PaintScaleFactory[T] {\n  override def apply(items : Traversable[T]) : PaintScale[T] = {\n    val distinct = items.toList.distinct;\n    CategoricalPaintScale[T](Map() ++ (distinct zip Stream.continually(PaintScale.Category20.values.toList).flatten));\n  }\n}\n\nobject PaintScaleFactory {\n\n  /**\n   * Ignores incoming data, instead returns the provided PaintScale when\n   * queried as a PaintScaleFactory.\n   */\n  implicit def singletonFactoryForPaintScale[S,T](paintScale : S)\n  (implicit view : S=>PaintScale[T])\n  : PaintScaleFactory[T] = new PaintScaleFactory[T] {\n    def apply(items : Traversable[T]) = view(paintScale);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/XYPlot.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\npackage plotting;\n\nimport org.jfree.chart.JFreeChart;\nimport org.jfree.chart.plot.DefaultDrawingSupplier;\nimport org.jfree.chart.axis.{NumberAxis,TickUnits,NumberTickUnit};\n\n/** A two dimensional XY plot */\nclass XYPlot(figure : Figure) {\n\n  val xaxis : NumberAxis = new NumberAxis(null);\n  val yaxis : NumberAxis = new NumberAxis(null);\n\n  // Save the default tick units.\n  private val xaxisDefaultTickUnits = xaxis.getStandardTickUnits();\n  private val yaxisDefaultTickUnits = yaxis.getStandardTickUnits();\n\n  def setXAxisIntegerTickUnits() = xaxis.setStandardTickUnits(XYPlot.integerTickUnits);\n  def setYAxisIntegerTickUnits() = yaxis.setStandardTickUnits(XYPlot.integerTickUnits);\n  def setXAxisDecimalTickUnits() = xaxis.setStandardTickUnits(xaxisDefaultTickUnits);\n  def setYAxisDecimalTickUnits() = yaxis.setStandardTickUnits(yaxisDefaultTickUnits);\n\n  // set integer tick units by default\n  Array(xaxis,yaxis) foreach (axis => {\n    axis.setAutoRangeIncludesZero(false);\n    axis.setStandardTickUnits(XYPlot.integerTickUnits);\n  });\n\n  /** The JFreeChart plot object. */  \n  lazy val plot = {\n    val rv = new org.jfree.chart.plot.XYPlot();\n    rv.setDomainAxis(xaxis)\n    rv.setRangeAxis(yaxis)\n  \n    rv.setDrawingSupplier(new DefaultDrawingSupplier(\n      XYPlot.paints,\n      XYPlot.fillPaints,\n      XYPlot.outlinePaints,\n      XYPlot.strokes,\n      XYPlot.outlineStrokes,\n      XYPlot.shapes));\n    \n    rv;\n  }\n\n  /** Adds to the current plot if true, else replaces */\n  var hold : Boolean = false\n  \n  /** The plot title */\n  def title_=(str : String) : Unit = chart.setTitle(str);\n  def title : String = chart.getTitle.getText;\n\n  /** If we show a legend */\n  private var _legend : Boolean = false;\n  def legend_=(show : Boolean) : Unit = {\n    chart.removeLegend();\n    if (show) {\n      import org.jfree.chart.title._;\n      import org.jfree.ui._;\n      import org.jfree.chart.block._;\n      import java.awt.Color;\n      val legend = new LegendTitle(this.plot);\n      legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));\n      legend.setFrame(new LineBorder());\n      legend.setBackgroundPaint(Color.WHITE);\n      legend.setPosition(RectangleEdge.BOTTOM);\n      chart.addLegend(legend);\n    }\n    _legend = show\n    refresh()\n  }\n  def legend : Boolean = _legend\n\n  /** The current series */\n  private var _series : Int = -1\n  def series = _series\n\n  /** Returns the next series number as per the current hold policy */\n  def nextSeries : Int = {\n    if (hold) {\n      _series += 1\n    } else {\n      _series = 0\n      for (i <- 0 until plot.getDatasetCount()) {\n        plot.setDataset(i,null);\n        plot.setRenderer(i,null);\n      }\n      // remove all subtitles, particularly so we can kill all legends\n      while (chart.getSubtitleCount > 0) {\n        chart.removeSubtitle(chart.getSubtitle(0));\n      }\n      // re-add the (now-empty) legend for consistency\n      legend = _legend;\n      // reset to integer ticks\n      setXAxisIntegerTickUnits();\n      setYAxisIntegerTickUnits();\n    }\n    return _series\n  }\n\n  /** The JFreeChart for this plot */\n  lazy val chart = {\n    val rv = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);\n    rv.setBackgroundPaint(XYPlot.transparent);\n    rv.setPadding(new org.jfree.ui.RectangleInsets(5,0,0,0));\n    rv;\n  }\n\n  /** The ChartPanel for this plot */\n  lazy val panel =\n    new org.jfree.chart.ChartPanel(chart);\n\n  /** Shows the given chart */\n  def refresh() = figure.refresh()\n}\n\nobject XYPlot {\n  import java.awt.{Color,Paint};\n  import org.jfree.chart.ChartColor._;\n  import org.jfree.chart.plot.DefaultDrawingSupplier;\n\n  /** Units for integer ticks on axes. */\n  val integerTickUnits = {\n    val units = new TickUnits();\n    val df = new java.text.DecimalFormat(\"0\");\n    for (b <- List(1,2,5); e <- List(0,1,2,3,4,5,6,7,8)) {\n      units.add(new NumberTickUnit(b * math.pow(10,e).toInt, df));\n    }\n    units;\n  }\n\n  // color cycle ignoring bright colors\n  val paints : Array[Paint] = PaintScale.Category20.values.asInstanceOf[Array[Paint]];\n  \n  def paint(series : Int) =\n    paints(series % paints.length);\n\n  val shapes = DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;\n  def shape(series : Int) =\n    shapes(series % shapes.length);\n\n  val strokes = DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE;\n  def stroke(series : Int) =\n    strokes(series % strokes.length);\n\n  val fillPaints = paints; // DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE;\n  def fillPaint(series : Int) =\n    fillPaints(series % fillPaints.length);\n\n  val outlinePaints = paints; // DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE;\n  def outlinePaint(series : Int) =\n    outlinePaints(series % outlinePaints.length);\n\n  val outlineStrokes = DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE;\n  def outlineStroke(series : Int) =\n    outlineStrokes(series % outlineStrokes.length);\n \n  val transparent = new Color(255,255,255,0);\n\n  //\n  // shapes\n  //\n  \n  val dot =\n    new java.awt.geom.Ellipse2D.Double(-1,-1,2,2);\n\n  val plus = {\n    val shape = new java.awt.geom.GeneralPath();\n    shape.moveTo(-3,0);\n    shape.lineTo(3,0);\n    shape.moveTo(0,-3);\n    shape.lineTo(0,3);\n    shape;\n  };\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/BinaryOp.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n \npackage scalala;\npackage operators;\n\nimport scala.annotation.implicitNotFound;\nimport scala.collection.generic.CanBuildFrom;\n\nimport scalala.scalar.Scalar;\n\n/**\n * Operation of type O that returns That from arguments A and B.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"Could not find a way to ${O} values of type ${A} and ${B}\")\ntrait BinaryOp[@specialized -A, @specialized -B, O<:OpType, +To]\nextends ((A,B) => To) {\n  def opType : O;\n}\n\ntrait BinaryOpImplicitsLevel0 {\n  /**\n   * Recursively add together the values from two maps.  Assumes all keys\n   * are in both maps.\n   */\n  implicit def OpRecurseMapMap[K,V1,V2,RV,O<:OpType,M,That]\n  (implicit view : M=>scala.collection.Map[K,V1],\n    op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2],\n    bf : CanBuildFrom[M,(K,RV),That])\n  : BinaryOp[M, scala.collection.Map[K,V2], O, That]\n  = new BinaryOp[M, scala.collection.Map[K,V2], O, That] {\n    def opType = op.opType;\n    def apply(a : M, b : scala.collection.Map[K,V2]) = {\n      val builder = bf(a);\n      for (k <- (a.keySet | b.keySet)) {\n        builder += k -> op(a(k),b(k));\n      }\n      builder.result;\n    }\n  }\n}\n\nobject BinaryOp extends BinaryTupleOps with BinaryOpImplicitsLevel0 {\n\n  // Int <-> Int\n\n  implicit object OpAddII extends BinaryOp[Int,Int,OpAdd,Int]\n    { def opType = OpAdd; def apply(a : Int, b : Int) = a + b; }\n  \n  implicit object OpSubII extends BinaryOp[Int,Int,OpSub,Int]\n    { def opType = OpSub; def apply(a : Int, b : Int) = a - b; }\n  \n  implicit object OpMulII extends BinaryOp[Int,Int,OpMul,Int]\n    { def opType = OpMul; def apply(a : Int, b : Int) = a * b; }\n  \n  implicit object OpDivII extends BinaryOp[Int,Int,OpDiv,Int]\n    { def opType = OpDiv; def apply(a : Int, b : Int) = a / b; }\n  \n  implicit object OpModII extends BinaryOp[Int,Int,OpMod,Int]\n    { def opType = OpMod; def apply(a : Int, b : Int) = a % b; }\n  \n  implicit object OpPowII extends BinaryOp[Int,Int,OpPow,Double]\n    { def opType = OpPow; def apply(a : Int, b : Int) = math.pow(a,b); }\n  \n  implicit object OpLTII extends BinaryOp[Int,Int,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Int, b : Int) = a < b; }\n  \n  implicit object OpLTEII extends BinaryOp[Int,Int,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Int, b : Int) = a <= b; }\n  \n  implicit object OpGTII extends BinaryOp[Int,Int,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Int, b : Int) = a > b; }\n  \n  implicit object OpGTEII extends BinaryOp[Int,Int,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Int, b : Int) = a >= b; }\n  \n  implicit object OpEqII extends BinaryOp[Int,Int,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Int, b : Int) = a == b; }\n  \n  implicit object OpNeII extends BinaryOp[Int,Int,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Int, b : Int) = a != b; }\n  \n  implicit object OpAndII extends BinaryOp[Int,Int,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Int, b : Int) = a != 0 && b != 0; }\n  \n  implicit object OpOrII extends BinaryOp[Int,Int,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Int, b : Int) = a != 0 || b != 0; }\n\n  implicit object OpXorII extends BinaryOp[Int,Int,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Int, b : Int) = (a != 0) ^ (b != 0); }\n\n  // Long <-> Long\n\n  implicit object OpAddLL extends BinaryOp[Long,Long,OpAdd,Long]\n    { def opType = OpAdd; def apply(a : Long, b : Long) = a + b; }\n  \n  implicit object OpSubLL extends BinaryOp[Long,Long,OpSub,Long]\n    { def opType = OpSub; def apply(a : Long, b : Long) = a - b; }\n  \n  implicit object OpMulLL extends BinaryOp[Long,Long,OpMul,Long]\n    { def opType = OpMul; def apply(a : Long, b : Long) = a * b; }\n  \n  implicit object OpDivLL extends BinaryOp[Long,Long,OpDiv,Long]\n    { def opType = OpDiv; def apply(a : Long, b : Long) = a / b; }\n  \n  implicit object OpModLL extends BinaryOp[Long,Long,OpMod,Long]\n    { def opType = OpMod; def apply(a : Long, b : Long) = a % b; }\n  \n  implicit object OpPowLL extends BinaryOp[Long,Long,OpPow,Double]\n    { def opType = OpPow; def apply(a : Long, b : Long) = math.pow(a,b); }\n  \n  implicit object OpLTLL extends BinaryOp[Long,Long,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Long, b : Long) = a < b; }\n  \n  implicit object OpLTELL extends BinaryOp[Long,Long,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Long, b : Long) = a <= b; }\n  \n  implicit object OpGTLL extends BinaryOp[Long,Long,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Long, b : Long) = a > b; }\n  \n  implicit object OpGTELL extends BinaryOp[Long,Long,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Long, b : Long) = a >= b; }\n  \n  implicit object OpEqLL extends BinaryOp[Long,Long,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Long, b : Long) = a == b; }\n  \n  implicit object OpNeLL extends BinaryOp[Long,Long,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Long, b : Long) = a != b; }\n  \n  implicit object OpAndLL extends BinaryOp[Long,Long,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Long, b : Long) = a != 0 && b != 0; }\n  \n  implicit object OpOrLL extends BinaryOp[Long,Long,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Long, b : Long) = a != 0 || b != 0; }\n\n  implicit object OpXorLL extends BinaryOp[Long,Long,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Long, b : Long) = (a != 0) ^ (b != 0); }\n    \n  // Float <-> Float\n\n  implicit object OpAddFF extends BinaryOp[Float,Float,OpAdd,Float]\n    { def opType = OpAdd; def apply(a : Float, b : Float) = a + b; }\n  \n  implicit object OpSubFF extends BinaryOp[Float,Float,OpSub,Float]\n    { def opType = OpSub; def apply(a : Float, b : Float) = a - b; }\n  \n  implicit object OpMulFF extends BinaryOp[Float,Float,OpMul,Float]\n    { def opType = OpMul; def apply(a : Float, b : Float) = a * b; }\n  \n  implicit object OpDivFF extends BinaryOp[Float,Float,OpDiv,Float]\n    { def opType = OpDiv; def apply(a : Float, b : Float) = a / b; }\n  \n  implicit object OpModFF extends BinaryOp[Float,Float,OpMod,Float]\n    { def opType = OpMod; def apply(a : Float, b : Float) = a % b; }\n  \n  implicit object OpPowFF extends BinaryOp[Float,Float,OpPow,Double]\n    { def opType = OpPow; def apply(a : Float, b : Float) = math.pow(a,b); }\n  \n  implicit object OpLTFF extends BinaryOp[Float,Float,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Float, b : Float) = a < b; }\n  \n  implicit object OpLTEFF extends BinaryOp[Float,Float,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Float, b : Float) = a <= b; }\n  \n  implicit object OpGTFF extends BinaryOp[Float,Float,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Float, b : Float) = a > b; }\n  \n  implicit object OpGTEFF extends BinaryOp[Float,Float,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Float, b : Float) = a >= b; }\n  \n  implicit object OpEqFF extends BinaryOp[Float,Float,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Float, b : Float) = a == b; }\n  \n  implicit object OpNeFF extends BinaryOp[Float,Float,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Float, b : Float) = a != b; }\n  \n  implicit object OpAndFF extends BinaryOp[Float,Float,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Float, b : Float) = a != 0 && b != 0; }\n  \n  implicit object OpOrFF extends BinaryOp[Float,Float,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Float, b : Float) = a != 0 || b != 0; }\n\n  implicit object OpXorFF extends BinaryOp[Float,Float,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Float, b : Float) = (a != 0) ^ (b != 0); }\n    \n  // Double <-> Double\n  \n  implicit object OpAddDD extends BinaryOp[Double,Double,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Double, b : Double) = a + b; }\n  \n  implicit object OpSubDD extends BinaryOp[Double,Double,OpSub,Double]\n    { def opType = OpSub; def apply(a : Double, b : Double) = a - b; }\n  \n  implicit object OpMulDD extends BinaryOp[Double,Double,OpMul,Double]\n    { def opType = OpMul; def apply(a : Double, b : Double) = a * b; }\n  \n  implicit object OpDivDD extends BinaryOp[Double,Double,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Double, b : Double) = a / b; }\n  \n  implicit object OpModDD extends BinaryOp[Double,Double,OpMod,Double]\n    { def opType = OpMod; def apply(a : Double, b : Double) = a % b; }\n  \n  implicit object OpPowDD extends BinaryOp[Double,Double,OpPow,Double]\n    { def opType = OpPow; def apply(a : Double, b : Double) = math.pow(a,b); }\n  \n  implicit object OpLTDD extends BinaryOp[Double,Double,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Double, b : Double) = a < b; }\n  \n  implicit object OpLTEDD extends BinaryOp[Double,Double,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Double, b : Double) = a <= b; }\n  \n  implicit object OpGTDD extends BinaryOp[Double,Double,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Double, b : Double) = a > b; }\n  \n  implicit object OpGTEDD extends BinaryOp[Double,Double,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Double, b : Double) = a >= b; }\n  \n  implicit object OpEqDD extends BinaryOp[Double,Double,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Double, b : Double) = a == b; }\n  \n  implicit object OpNeDD extends BinaryOp[Double,Double,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Double, b : Double) = a != b; }\n  \n  implicit object OpAndDD extends BinaryOp[Double,Double,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Double, b : Double) = a != 0 && b != 0; }\n  \n  implicit object OpOrDD extends BinaryOp[Double,Double,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Double, b : Double) = a != 0 || b != 0; }\n\n  implicit object OpXorDD extends BinaryOp[Double,Double,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Double, b : Double) = (a != 0) ^ (b != 0); }\n  \n  // Int <-> Double\n  \n  implicit object OpAddID extends BinaryOp[Int,Double,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Int, b : Double) = a + b; }\n  \n  implicit object OpSubID extends BinaryOp[Int,Double,OpSub,Double]\n    { def opType = OpSub; def apply(a : Int, b : Double) = a - b; }\n  \n  implicit object OpMulID extends BinaryOp[Int,Double,OpMul,Double]\n    { def opType = OpMul; def apply(a : Int, b : Double) = a * b; }\n  \n  implicit object OpDivID extends BinaryOp[Int,Double,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Int, b : Double) = a / b; }\n  \n  implicit object OpModID extends BinaryOp[Int,Double,OpMod,Double]\n    { def opType = OpMod; def apply(a : Int, b : Double) = a % b; }\n  \n  implicit object OpPowID extends BinaryOp[Int,Double,OpPow,Double]\n    { def opType = OpPow; def apply(a : Int, b : Double) = math.pow(a,b); }\n    \n  implicit object OpLTID extends BinaryOp[Int,Double,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Int, b : Double) = a < b; }\n  \n  implicit object OpLTEID extends BinaryOp[Int,Double,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Int, b : Double) = a <= b; }\n  \n  implicit object OpGTID extends BinaryOp[Int,Double,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Int, b : Double) = a > b; }\n  \n  implicit object OpGTEID extends BinaryOp[Int,Double,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Int, b : Double) = a >= b; }\n  \n  implicit object OpEqID extends BinaryOp[Int,Double,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Int, b : Double) = a == b; }\n  \n  implicit object OpNeID extends BinaryOp[Int,Double,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Int, b : Double) = a != b; }\n  \n  implicit object OpAndID extends BinaryOp[Int,Double,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Int, b : Double) = a != 0 && b != 0; }\n  \n  implicit object OpOrID extends BinaryOp[Int,Double,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Int, b : Double) = a != 0 || b != 0; }\n\n  implicit object OpXorID extends BinaryOp[Int,Double,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Int, b : Double) = (a != 0) ^ (b != 0); }\n    \n  // Double <-> Int\n  \n  implicit object OpAddDI extends BinaryOp[Double,Int,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Double, b : Int) = a + b; }\n  \n  implicit object OpSubDI extends BinaryOp[Double,Int,OpSub,Double]\n    { def opType = OpSub; def apply(a : Double, b : Int) = a - b; }\n  \n  implicit object OpMulDI extends BinaryOp[Double,Int,OpMul,Double]\n    { def opType = OpMul; def apply(a : Double, b : Int) = a * b; }\n  \n  implicit object OpDivDI extends BinaryOp[Double,Int,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Double, b : Int) = a / b; }\n  \n  implicit object OpModDI extends BinaryOp[Double,Int,OpMod,Double]\n    { def opType = OpMod; def apply(a : Double, b : Int) = a % b; }\n  \n  implicit object OpPowDI extends BinaryOp[Double,Int,OpPow,Double]\n    { def opType = OpPow; def apply(a : Double, b : Int) = math.pow(a,b); }\n    \n  implicit object OpLTDI extends BinaryOp[Double,Int,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Double, b : Int) = a < b; }\n  \n  implicit object OpLTEDI extends BinaryOp[Double,Int,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Double, b : Int) = a <= b; }\n  \n  implicit object OpGTDI extends BinaryOp[Double,Int,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Double, b : Int) = a > b; }\n  \n  implicit object OpGTEDI extends BinaryOp[Double,Int,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Double, b : Int) = a >= b; }\n  \n  implicit object OpEqDI extends BinaryOp[Double,Int,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Double, b : Int) = a == b; }\n  \n  implicit object OpNeDI extends BinaryOp[Double,Int,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Double, b : Int) = a != b; }\n  \n  implicit object OpAndDI extends BinaryOp[Double,Int,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Double, b : Int) = a != 0 && b != 0; }\n  \n  implicit object OpOrDI extends BinaryOp[Double,Int,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Double, b : Int) = a != 0 || b != 0; }\n\n  implicit object OpXorDI extends BinaryOp[Double,Int,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Double, b : Int) = (a != 0) ^ (b != 0); }\n\n  // Int <-> Float\n  \n  implicit object OpAddIF extends BinaryOp[Int,Float,OpAdd,Float]\n    { def opType = OpAdd; def apply(a : Int, b : Float) = a + b; }\n  \n  implicit object OpSubIF extends BinaryOp[Int,Float,OpSub,Float]\n    { def opType = OpSub; def apply(a : Int, b : Float) = a - b; }\n  \n  implicit object OpMulIF extends BinaryOp[Int,Float,OpMul,Float]\n    { def opType = OpMul; def apply(a : Int, b : Float) = a * b; }\n  \n  implicit object OpDivIF extends BinaryOp[Int,Float,OpDiv,Float]\n    { def opType = OpDiv; def apply(a : Int, b : Float) = a / b; }\n  \n  implicit object OpModIF extends BinaryOp[Int,Float,OpMod,Float]\n    { def opType = OpMod; def apply(a : Int, b : Float) = a % b; }\n  \n  implicit object OpPowIF extends BinaryOp[Int,Float,OpPow,Double]\n    { def opType = OpPow; def apply(a : Int, b : Float) = math.pow(a,b); }\n    \n  implicit object OpLTIF extends BinaryOp[Int,Float,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Int, b : Float) = a < b; }\n  \n  implicit object OpLTEIF extends BinaryOp[Int,Float,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Int, b : Float) = a <= b; }\n  \n  implicit object OpGTIF extends BinaryOp[Int,Float,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Int, b : Float) = a > b; }\n  \n  implicit object OpGTEIF extends BinaryOp[Int,Float,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Int, b : Float) = a >= b; }\n  \n  implicit object OpEqIF extends BinaryOp[Int,Float,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Int, b : Float) = a == b; }\n  \n  implicit object OpNeIF extends BinaryOp[Int,Float,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Int, b : Float) = a != b; }\n  \n  implicit object OpAndIF extends BinaryOp[Int,Float,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Int, b : Float) = a != 0 && b != 0; }\n  \n  implicit object OpOrIF extends BinaryOp[Int,Float,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Int, b : Float) = a != 0 || b != 0; }\n\n  implicit object OpXorIF extends BinaryOp[Int,Float,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Int, b : Float) = (a != 0) ^ (b != 0); }\n    \n  // Float <-> Int\n  \n  implicit object OpAddFI extends BinaryOp[Float,Int,OpAdd,Float]\n    { def opType = OpAdd; def apply(a : Float, b : Int) = a + b; }\n  \n  implicit object OpSubFI extends BinaryOp[Float,Int,OpSub,Float]\n    { def opType = OpSub; def apply(a : Float, b : Int) = a - b; }\n  \n  implicit object OpMulFI extends BinaryOp[Float,Int,OpMul,Float]\n    { def opType = OpMul; def apply(a : Float, b : Int) = a * b; }\n  \n  implicit object OpDivFI extends BinaryOp[Float,Int,OpDiv,Float]\n    { def opType = OpDiv; def apply(a : Float, b : Int) = a / b; }\n  \n  implicit object OpModFI extends BinaryOp[Float,Int,OpMod,Float]\n    { def opType = OpMod; def apply(a : Float, b : Int) = a % b; }\n  \n  implicit object OpPowFI extends BinaryOp[Float,Int,OpPow,Double]\n    { def opType = OpPow; def apply(a : Float, b : Int) = math.pow(a,b); }\n    \n  implicit object OpLTFI extends BinaryOp[Float,Int,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Float, b : Int) = a < b; }\n  \n  implicit object OpLTEFI extends BinaryOp[Float,Int,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Float, b : Int) = a <= b; }\n  \n  implicit object OpGTFI extends BinaryOp[Float,Int,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Float, b : Int) = a > b; }\n  \n  implicit object OpGTEFI extends BinaryOp[Float,Int,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Float, b : Int) = a >= b; }\n  \n  implicit object OpEqFI extends BinaryOp[Float,Int,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Float, b : Int) = a == b; }\n  \n  implicit object OpNeFI extends BinaryOp[Float,Int,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Float, b : Int) = a != b; }\n  \n  implicit object OpAndFI extends BinaryOp[Float,Int,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Float, b : Int) = a != 0 && b != 0; }\n  \n  implicit object OpOrFI extends BinaryOp[Float,Int,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Float, b : Int) = a != 0 || b != 0; }\n\n  implicit object OpXorFI extends BinaryOp[Float,Int,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Float, b : Int) = (a != 0) ^ (b != 0); }\n  \n  // Int <-> Long\n  \n  implicit object OpAddIL extends BinaryOp[Int,Long,OpAdd,Long]\n    { def opType = OpAdd; def apply(a : Int, b : Long) = a + b; }\n  \n  implicit object OpSubIL extends BinaryOp[Int,Long,OpSub,Long]\n    { def opType = OpSub; def apply(a : Int, b : Long) = a - b; }\n  \n  implicit object OpMulIL extends BinaryOp[Int,Long,OpMul,Long]\n    { def opType = OpMul; def apply(a : Int, b : Long) = a * b; }\n  \n  implicit object OpDivIL extends BinaryOp[Int,Long,OpDiv,Long]\n    { def opType = OpDiv; def apply(a : Int, b : Long) = a / b; }\n  \n  implicit object OpModIL extends BinaryOp[Int,Long,OpMod,Long]\n    { def opType = OpMod; def apply(a : Int, b : Long) = a % b; }\n  \n  implicit object OpPowIL extends BinaryOp[Int,Long,OpPow,Double]\n    { def opType = OpPow; def apply(a : Int, b : Long) = math.pow(a,b); }\n    \n  implicit object OpLTIL extends BinaryOp[Int,Long,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Int, b : Long) = a < b; }\n  \n  implicit object OpLTEIL extends BinaryOp[Int,Long,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Int, b : Long) = a <= b; }\n  \n  implicit object OpGTIL extends BinaryOp[Int,Long,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Int, b : Long) = a > b; }\n  \n  implicit object OpGTEIL extends BinaryOp[Int,Long,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Int, b : Long) = a >= b; }\n  \n  implicit object OpEqIL extends BinaryOp[Int,Long,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Int, b : Long) = a == b; }\n  \n  implicit object OpNeIL extends BinaryOp[Int,Long,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Int, b : Long) = a != b; }\n  \n  implicit object OpAndIL extends BinaryOp[Int,Long,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Int, b : Long) = a != 0 && b != 0; }\n  \n  implicit object OpOrIL extends BinaryOp[Int,Long,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Int, b : Long) = a != 0 || b != 0; }\n\n  implicit object OpXorIL extends BinaryOp[Int,Long,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Int, b : Long) = (a != 0) ^ (b != 0); }\n    \n  // Long <-> Int\n  \n  implicit object OpAddLI extends BinaryOp[Long,Int,OpAdd,Long]\n    { def opType = OpAdd; def apply(a : Long, b : Int) = a + b; }\n  \n  implicit object OpSubLI extends BinaryOp[Long,Int,OpSub,Long]\n    { def opType = OpSub; def apply(a : Long, b : Int) = a - b; }\n  \n  implicit object OpMulLI extends BinaryOp[Long,Int,OpMul,Long]\n    { def opType = OpMul; def apply(a : Long, b : Int) = a * b; }\n  \n  implicit object OpDivLI extends BinaryOp[Long,Int,OpDiv,Long]\n    { def opType = OpDiv; def apply(a : Long, b : Int) = a / b; }\n  \n  implicit object OpModLI extends BinaryOp[Long,Int,OpMod,Long]\n    { def opType = OpMod; def apply(a : Long, b : Int) = a % b; }\n  \n  implicit object OpPowLI extends BinaryOp[Long,Int,OpPow,Double]\n    { def opType = OpPow; def apply(a : Long, b : Int) = math.pow(a,b); }\n    \n  implicit object OpLTLI extends BinaryOp[Long,Int,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Long, b : Int) = a < b; }\n  \n  implicit object OpLTELI extends BinaryOp[Long,Int,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Long, b : Int) = a <= b; }\n  \n  implicit object OpGTLI extends BinaryOp[Long,Int,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Long, b : Int) = a > b; }\n  \n  implicit object OpGTELI extends BinaryOp[Long,Int,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Long, b : Int) = a >= b; }\n  \n  implicit object OpEqLI extends BinaryOp[Long,Int,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Long, b : Int) = a == b; }\n  \n  implicit object OpNeLI extends BinaryOp[Long,Int,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Long, b : Int) = a != b; }\n  \n  implicit object OpAndLI extends BinaryOp[Long,Int,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Long, b : Int) = a != 0 && b != 0; }\n  \n  implicit object OpOrLI extends BinaryOp[Long,Int,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Long, b : Int) = a != 0 || b != 0; }\n\n  implicit object OpXorLI extends BinaryOp[Long,Int,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Long, b : Int) = (a != 0) ^ (b != 0); }\n  \n  // Float <-> Double\n  \n  implicit object OpAddFD extends BinaryOp[Float,Double,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Float, b : Double) = a + b; }\n  \n  implicit object OpSubFD extends BinaryOp[Float,Double,OpSub,Double]\n    { def opType = OpSub; def apply(a : Float, b : Double) = a - b; }\n  \n  implicit object OpMulFD extends BinaryOp[Float,Double,OpMul,Double]\n    { def opType = OpMul; def apply(a : Float, b : Double) = a * b; }\n  \n  implicit object OpDivFD extends BinaryOp[Float,Double,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Float, b : Double) = a / b; }\n  \n  implicit object OpModFD extends BinaryOp[Float,Double,OpMod,Double]\n    { def opType = OpMod; def apply(a : Float, b : Double) = a % b; }\n  \n  implicit object OpPowFD extends BinaryOp[Float,Double,OpPow,Double]\n    { def opType = OpPow; def apply(a : Float, b : Double) = math.pow(a,b); }\n    \n  implicit object OpLTFD extends BinaryOp[Float,Double,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Float, b : Double) = a < b; }\n  \n  implicit object OpLTEFD extends BinaryOp[Float,Double,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Float, b : Double) = a <= b; }\n  \n  implicit object OpGTFD extends BinaryOp[Float,Double,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Float, b : Double) = a > b; }\n  \n  implicit object OpGTEFD extends BinaryOp[Float,Double,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Float, b : Double) = a >= b; }\n  \n  implicit object OpEqFD extends BinaryOp[Float,Double,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Float, b : Double) = a == b; }\n  \n  implicit object OpNeFD extends BinaryOp[Float,Double,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Float, b : Double) = a != b; }\n  \n  implicit object OpAndFD extends BinaryOp[Float,Double,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Float, b : Double) = a != 0 && b != 0; }\n  \n  implicit object OpOrFD extends BinaryOp[Float,Double,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Float, b : Double) = a != 0 || b != 0; }\n\n  implicit object OpXorFD extends BinaryOp[Float,Double,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Float, b : Double) = (a != 0) ^ (b != 0); }\n    \n  // Double <-> Float\n  \n  implicit object OpAddDF extends BinaryOp[Double,Float,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Double, b : Float) = a + b; }\n  \n  implicit object OpSubDF extends BinaryOp[Double,Float,OpSub,Double]\n    { def opType = OpSub; def apply(a : Double, b : Float) = a - b; }\n  \n  implicit object OpMulDF extends BinaryOp[Double,Float,OpMul,Double]\n    { def opType = OpMul; def apply(a : Double, b : Float) = a * b; }\n  \n  implicit object OpDivDF extends BinaryOp[Double,Float,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Double, b : Float) = a / b; }\n  \n  implicit object OpModDF extends BinaryOp[Double,Float,OpMod,Double]\n    { def opType = OpMod; def apply(a : Double, b : Float) = a % b; }\n  \n  implicit object OpPowDF extends BinaryOp[Double,Float,OpPow,Double]\n    { def opType = OpPow; def apply(a : Double, b : Float) = math.pow(a,b); }\n    \n  implicit object OpLTDF extends BinaryOp[Double,Float,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Double, b : Float) = a < b; }\n  \n  implicit object OpLTEDF extends BinaryOp[Double,Float,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Double, b : Float) = a <= b; }\n  \n  implicit object OpGTDF extends BinaryOp[Double,Float,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Double, b : Float) = a > b; }\n  \n  implicit object OpGTEDF extends BinaryOp[Double,Float,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Double, b : Float) = a >= b; }\n  \n  implicit object OpEqDF extends BinaryOp[Double,Float,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Double, b : Float) = a == b; }\n  \n  implicit object OpNeDF extends BinaryOp[Double,Float,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Double, b : Float) = a != b; }\n  \n  implicit object OpAndDF extends BinaryOp[Double,Float,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Double, b : Float) = a != 0 && b != 0; }\n  \n  implicit object OpOrDF extends BinaryOp[Double,Float,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Double, b : Float) = a != 0 || b != 0; }\n\n  implicit object OpXorDF extends BinaryOp[Double,Float,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Double, b : Float) = (a != 0) ^ (b != 0); }\n\n  // Long <-> Double\n  \n  implicit object OpAddLD extends BinaryOp[Long,Double,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Long, b : Double) = a + b; }\n  \n  implicit object OpSubLD extends BinaryOp[Long,Double,OpSub,Double]\n    { def opType = OpSub; def apply(a : Long, b : Double) = a - b; }\n  \n  implicit object OpMulLD extends BinaryOp[Long,Double,OpMul,Double]\n    { def opType = OpMul; def apply(a : Long, b : Double) = a * b; }\n  \n  implicit object OpDivLD extends BinaryOp[Long,Double,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Long, b : Double) = a / b; }\n  \n  implicit object OpModLD extends BinaryOp[Long,Double,OpMod,Double]\n    { def opType = OpMod; def apply(a : Long, b : Double) = a % b; }\n  \n  implicit object OpPowLD extends BinaryOp[Long,Double,OpPow,Double]\n    { def opType = OpPow; def apply(a : Long, b : Double) = math.pow(a,b); }\n    \n  implicit object OpLTLD extends BinaryOp[Long,Double,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Long, b : Double) = a < b; }\n  \n  implicit object OpLTELD extends BinaryOp[Long,Double,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Long, b : Double) = a <= b; }\n  \n  implicit object OpGTLD extends BinaryOp[Long,Double,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Long, b : Double) = a > b; }\n  \n  implicit object OpGTELD extends BinaryOp[Long,Double,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Long, b : Double) = a >= b; }\n  \n  implicit object OpEqLD extends BinaryOp[Long,Double,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Long, b : Double) = a == b; }\n  \n  implicit object OpNeLD extends BinaryOp[Long,Double,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Long, b : Double) = a != b; }\n  \n  implicit object OpAndLD extends BinaryOp[Long,Double,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Long, b : Double) = a != 0 && b != 0; }\n  \n  implicit object OpOrLD extends BinaryOp[Long,Double,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Long, b : Double) = a != 0 || b != 0; }\n\n  implicit object OpXorLD extends BinaryOp[Long,Double,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Long, b : Double) = (a != 0) ^ (b != 0); }\n    \n  // Double <-> Long\n  \n  implicit object OpAddDL extends BinaryOp[Double,Long,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Double, b : Long) = a + b; }\n  \n  implicit object OpSubDL extends BinaryOp[Double,Long,OpSub,Double]\n    { def opType = OpSub; def apply(a : Double, b : Long) = a - b; }\n  \n  implicit object OpMulDL extends BinaryOp[Double,Long,OpMul,Double]\n    { def opType = OpMul; def apply(a : Double, b : Long) = a * b; }\n  \n  implicit object OpDivDL extends BinaryOp[Double,Long,OpDiv,Double]\n    { def opType = OpDiv; def apply(a : Double, b : Long) = a / b; }\n  \n  implicit object OpModDL extends BinaryOp[Double,Long,OpMod,Double]\n    { def opType = OpMod; def apply(a : Double, b : Long) = a % b; }\n  \n  implicit object OpPowDL extends BinaryOp[Double,Long,OpPow,Double]\n    { def opType = OpPow; def apply(a : Double, b : Long) = math.pow(a,b); }\n    \n  implicit object OpLTDL extends BinaryOp[Double,Long,OpLT,Boolean]\n    { def opType = OpLT; def apply(a : Double, b : Long) = a < b; }\n  \n  implicit object OpLTEDL extends BinaryOp[Double,Long,OpLTE,Boolean]\n    { def opType = OpLTE; def apply(a : Double, b : Long) = a <= b; }\n  \n  implicit object OpGTDL extends BinaryOp[Double,Long,OpGT,Boolean]\n    { def opType = OpGT; def apply(a : Double, b : Long) = a > b; }\n  \n  implicit object OpGTEDL extends BinaryOp[Double,Long,OpGTE,Boolean]\n    { def opType = OpGTE; def apply(a : Double, b : Long) = a >= b; }\n  \n  implicit object OpEqDL extends BinaryOp[Double,Long,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Double, b : Long) = a == b; }\n  \n  implicit object OpNeDL extends BinaryOp[Double,Long,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Double, b : Long) = a != b; }\n  \n  implicit object OpAndDL extends BinaryOp[Double,Long,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Double, b : Long) = a != 0 && b != 0; }\n  \n  implicit object OpOrDL extends BinaryOp[Double,Long,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Double, b : Long) = a != 0 || b != 0; }\n\n  implicit object OpXorDL extends BinaryOp[Double,Long,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Double, b : Long) = (a != 0) ^ (b != 0); }\n\n  // Boolean <-> Boolean\n  \n  implicit object OpEqBB extends BinaryOp[Boolean,Boolean,OpEq,Boolean]\n    { def opType = OpEq; def apply(a : Boolean, b : Boolean) = a == b; }\n  \n  implicit object OpNeBB extends BinaryOp[Boolean,Boolean,OpNe,Boolean]\n    { def opType = OpNe; def apply(a : Boolean, b : Boolean) = a != b; }\n  \n  implicit object OpAndBB extends BinaryOp[Boolean,Boolean,OpAnd,Boolean]\n    { def opType = OpAnd; def apply(a : Boolean, b : Boolean) = a && b; }\n  \n  implicit object OpOrBB extends BinaryOp[Boolean,Boolean,OpOr,Boolean]\n    { def opType = OpOr; def apply(a : Boolean, b : Boolean) = a || b; }\n\n  implicit object OpXorBB extends BinaryOp[Boolean,Boolean,OpXor,Boolean]\n    { def opType = OpXor; def apply(a : Boolean, b : Boolean) = a ^ b; }\n\n  // Boolean * Anything and vice versa\n\n  implicit object OpMulBB extends BinaryOp[Boolean,Boolean,OpMul,Boolean]\n    { def opType = OpMul; def apply(a : Boolean, b : Boolean) = a && b; }\n\n  implicit object OpMulBI extends BinaryOp[Boolean,Int,OpMul,Int]\n    { def opType = OpMul; def apply(a : Boolean, b : Int) = if (a) b else 0; }\n\n  implicit object OpMulBL extends BinaryOp[Boolean,Long,OpMul,Long]\n    { def opType = OpMul; def apply(a : Boolean, b : Long) = if (a) b else 0; }\n\n  implicit object OpMulBF extends BinaryOp[Boolean,Float,OpMul,Float]\n    { def opType = OpMul; def apply(a : Boolean, b : Float) = if (a) b else 0; }\n\n  implicit object OpMulBD extends BinaryOp[Boolean,Double,OpMul,Double]\n    { def opType = OpMul; def apply(a : Boolean, b : Double) = if (a) b else 0; }\n\n  implicit object OpMulIB extends BinaryOp[Int,Boolean,OpMul,Int]\n    { def opType = OpMul; def apply(a : Int, b : Boolean) = if (b) a else 0; }\n\n  implicit object OpMulLB extends BinaryOp[Long,Boolean,OpMul,Long]\n    { def opType = OpMul; def apply(a : Long, b : Boolean) = if (b) a else 0; }\n\n  implicit object OpMulFB extends BinaryOp[Float,Boolean,OpMul,Float]\n    { def opType = OpMul; def apply(a : Float, b : Boolean) = if (b) a else 0; }\n\n  implicit object OpMulDB extends BinaryOp[Double,Boolean,OpMul,Double]\n    { def opType = OpMul; def apply(a : Double, b : Boolean) = if (b) a else 0; }\n\n  implicit def OpMulBooleanAny[V](implicit s : Scalar[V])\n  : BinaryOp[Boolean,V,OpMul,V]\n  = new BinaryOp[Boolean,V,OpMul,V] {\n    def opType = OpMul; def apply(a : Boolean, b : V) = if (a) b else s.zero;\n  }\n\n  implicit def OpMulAnyBoolean[V](implicit s : Scalar[V])\n  : BinaryOp[V,Boolean,OpMul,V]\n  = new BinaryOp[V,Boolean,OpMul,V] {\n    def opType = OpMul; def apply(a : V, b : Boolean) = if (b) a else s.zero;\n  }\n\n  // Double <-> Boolean\n\n  implicit object OpAddDB extends BinaryOp[Double,Boolean,OpAdd,Double]\n    { def opType = OpAdd; def apply(a : Double, b : Boolean) = if(b) a + 1 else a; }\n\n  implicit object OpSubDB extends BinaryOp[Double,Boolean,OpSub,Double]\n    { def opType = OpSub; def apply(a : Double, b : Boolean) = if(b) a - 1 else a; }\n\n  implicit object OpPowDB extends BinaryOp[Double,Boolean,OpPow,Double]\n    { def opType = OpPow; def apply(a : Double, b : Boolean) = math.pow(a,if(b) 1.0 else 0.0); }\n\n  //\n  // Promote regular scalar multiplications to shaped multiplications\n  //\n  \n  implicit def promoteScalarMulToMulRowVectorBy[A,B,RV]\n  (implicit view : A=>scalala.tensor.Tensor1Row[_,_],\n   op : BinaryOp[A,B,OpMul,RV], s : Scalar[B])\n  : BinaryOp[A,B,OpMulRowVectorBy,RV]\n  = new BinaryOp[A,B,OpMulRowVectorBy,RV] {\n    def opType = OpMulRowVectorBy; def apply(a : A, b : B) = op(a,b);\n  }\n\n  implicit def promoteScalarMulToMulColVectorBy[A,B,RV]\n  (implicit view : A=>scalala.tensor.Tensor1Col[_,_],\n   op : BinaryOp[A,B,OpMul,RV], s : Scalar[B])\n  : BinaryOp[A,B,OpMulColVectorBy,RV]\n  = new BinaryOp[A,B,OpMulColVectorBy,RV] {\n    def opType = OpMulColVectorBy; def apply(a : A, b : B) = op(a,b);\n  }\n\n  implicit def promoteScalarMulToMulMatrixBy[A,B,RV]\n  (implicit view : A=>scalala.tensor.Tensor2[_,_,_],\n   op : BinaryOp[A,B,OpMul,RV], s : Scalar[B])\n  : BinaryOp[A,B,OpMulMatrixBy,RV]\n  = new BinaryOp[A,B,OpMulMatrixBy,RV] {\n    def opType = OpMulMatrixBy; def apply(a : A, b : B) = op(a,b);\n  }\n  \n  //\n  // Maps\n  //\n  \n  implicit def OpLeafMapMap[K,V1,V2,RV,O<:OpType,M,That]\n  (implicit view : M=>scala.collection.Map[K,V1],\n    op : BinaryOp[V1,V2,O,RV], s1 : Scalar[V1], s2 : Scalar[V2],\n    bf : CanBuildFrom[M,(K,RV),That])\n  : BinaryOp[M, scala.collection.Map[K,V2], O, That]\n  = new BinaryOp[M, scala.collection.Map[K,V2], O, That] {\n    def opType = op.opType;\n    def apply(a : M, b : scala.collection.Map[K,V2]) = {\n      val builder = bf(a);\n      for (k <- a.keySet) {\n        builder += k -> op(a(k), b.getOrElse(k, s2.zero));\n      }\n      for (k <- b.keySet) {\n        if (!a.contains(k)) {\n          builder += k -> op(s1.zero, b(k));\n        }\n      }\n      builder.result;\n    }\n  }\n  \n  implicit def OpMapScalar[K,V1,V2,RV,O<:OpType,M,That]\n  (implicit view : M=>scala.collection.Map[K,V1],\n    op : BinaryOp[V1,V2,O,RV], s : Scalar[V2],\n    bf : CanBuildFrom[M,(K,RV),That])\n  : BinaryOp[M, V2, O, That]\n  = new BinaryOp[M, V2, O, That] {\n    def opType = op.opType;\n    def apply(a : M, b : V2) = {\n      val builder = bf(a);\n      for ((k,v) <- a) {\n        builder += k -> op(v,b);\n      }\n      builder.result;\n    }\n  }\n  \n  implicit def OpScalarMap[K,V1,V2,RV,O<:OpType,M,That]\n  (implicit view : M=>scala.collection.Map[K,V2],\n    op : BinaryOp[V1,V2,O,RV], s : Scalar[V1],\n    bf : CanBuildFrom[M,(K,RV),That])\n  : BinaryOp[V1, M, O, That]\n  = new BinaryOp[V1, M, O, That] {\n    def opType = op.opType;\n    def apply(a : V1, b : M) = {\n      val builder = bf(b);\n      for ((k,v) <- b) {\n        builder += k -> op(a,v);\n      }\n      builder.result;\n    }\n  }\n  \n  //\n  // Seqs\n  //\n\n  implicit def OpSeqSeq[V1,V2,RV,O<:OpType,S,That]\n  (implicit view : S=>scala.collection.Seq[V1],\n   op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2],\n   bf : CanBuildFrom[S,RV,That])\n  : BinaryOp[S,scala.collection.Seq[V2],O,That]\n  = new BinaryOp[S,scala.collection.Seq[V2],O,That] {\n    def opType = op.opType;\n    def apply(a : S, b : scala.collection.Seq[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      val builder = bf(a);\n      for ((ai,bi) <- a.iterator zip b.iterator) {\n        builder += op(ai,bi);\n      }\n      builder.result;\n    }\n  }\n  \n  implicit def OpSeqScalar[V1,V2,RV,O<:OpType,S,That]\n  (implicit view : S=>scala.collection.Seq[V1],\n   op : BinaryOp[V1,V2,O,RV], s : Scalar[V2],\n   bf : CanBuildFrom[S,RV,That])\n  : BinaryOp[S, V2, O, That]\n  = new BinaryOp[S, V2, O, That] {\n    def opType = op.opType;\n    def apply(a : S, b : V2) = {\n      val builder = bf(a);\n      for (v <- a) builder += op(v, b);\n      builder.result;\n    }\n  }\n  \n  implicit def OpScalarSeq[V1,V2,RV,O<:OpType,S,That]\n  (implicit view : S=>scala.collection.Seq[V2],\n   op : BinaryOp[V1,V2,O,RV], s : Scalar[V1],\n   bf : CanBuildFrom[S,RV,That])\n  : BinaryOp[V1, S, O, That]\n  = new BinaryOp[V1, S, O, That] {\n    def opType = op.opType;\n    def apply(a : V1, b : S) = {\n      val builder = bf(b);\n      for (v <- b) builder += op(a, v);\n      builder.result;\n    }\n  }\n\n\n  //\n  // Arrays\n  //\n\n  implicit def OpArrayArray[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2], mf : Manifest[RV])\n  : BinaryOp[Array[V1],Array[V2],O,Array[RV]]\n  = new BinaryOp[Array[V1],Array[V2],O,Array[RV]] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var rv = new Array[RV](a.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = op(a(i),b(i));\n        i += 1;\n      }\n      rv;\n    }\n  }\n  \n  implicit def OpArrayScalar[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], s : Scalar[V2], mf : Manifest[RV])\n  : BinaryOp[Array[V1], V2, O, Array[RV]]\n  = new BinaryOp[Array[V1], V2, O, Array[RV]] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : V2) = {\n      var rv = new Array[RV](a.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = op(a(i),b);\n        i += 1;\n      }\n      rv;\n    }\n  }\n  \n  implicit def OpScalarArray[V1,V2,RV,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,RV], s : Scalar[V1], mf : Manifest[RV])\n  : BinaryOp[V1, Array[V2], O, Array[RV]]\n  = new BinaryOp[V1, Array[V2], O, Array[RV]] {\n    def opType = op.opType;\n    def apply(a : V1, b : Array[V2]) = {\n      var rv = new Array[RV](b.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = op(a,b(i));\n        i += 1;\n      }\n      rv;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/BinaryOpRegistry.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n \npackage scalala;\npackage operators;\n\nimport scala.annotation.implicitNotFound;\nimport scala.collection.generic.CanBuildFrom;\n\nimport scala.collection.mutable.HashMap;\n\nobject BinaryOpRegistry {\n  val resultTypes =\n    HashMap[(Manifest[_],Manifest[_],Manifest[_]),Manifest[_]]();\n  \n  val ops =\n    HashMap[(Manifest[_],Manifest[_],Manifest[_]),BinaryOp[_,_,_,_]]();\n  \n  def register[A,B,O<:OpType,To](implicit gen : BinaryOp[A,B,O,To], a : Manifest[A], b : Manifest[B], op : Manifest[O], to : Manifest[To]) = {\n    resultTypes((a,b,op)) = to\n    ops((a,b,op)) = gen\n  }\n  \n  def getResultType[A,B,O<:OpType](implicit a : Manifest[A], b : Manifest[B], op : Manifest[O]) =\n    resultTypes((a,b,op));\n  \n  def getBinaryOp[A,B,O<:OpType,To](implicit a : Manifest[A], b : Manifest[B], op : Manifest[O], to : Manifest[To]) : BinaryOp[A,B,O,To] = {\n    require(getResultType[A,B,O] == to, \"Mismatched result type: \"+to);\n    ops((a,b,op)).asInstanceOf[BinaryOp[A,B,O,To]]\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/BinaryUpdateOp.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scala.annotation.implicitNotFound;\nimport scalala.scalar.Scalar;\n\n/**\n * Operation of type O that updates A using B.  Example: A += B.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"Could not find a way to ${O} ${B} into ${A}\")\ntrait BinaryUpdateOp[@specialized -A, @specialized -B, O<:OpType]\nextends ((A,B) => Unit) {\n  def opType : O;\n}\n\n/**\n * Very low priority implicits.\n *\n * @author dramage\n */\ntrait BinaryUpdateOpImplicitsLevel0 {\n\n  //\n  // Seqs\n  //\n\n  /** Set mutable seq with corresponding value from another seq. */  \n  implicit def CanSetSeqSeqCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Seq[V1], scala.collection.Seq[V2], OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Seq[V1], scala.collection.Seq[V2], OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Seq[V1], b : scala.collection.Seq[V2]) = {\n      var i = 0;\n      for (v <- b) {\n        a(i) = cast(v);\n        i += 1;\n      }\n    }\n  }\n\n  /** Set mutable seq with cast scalar. */  \n  implicit def OpSetSeqScalarCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Seq[V1], V2, OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Seq[V1], V2, OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Seq[V1], b : V2) = {\n      val v = cast(b);\n      var i = 0;\n      while (i < a.length) {\n        a(i) = v;\n        i += 1;\n      }\n    }\n  }\n  \n  //\n  // Maps\n  //\n  \n  /** Set mutable map to cast values from another map. */\n  implicit def OpSetMapMapCast[K,V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Map[K,V1], scala.collection.Map[K,V2], OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Map[K,V1], scala.collection.Map[K,V2], OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Map[K,V1], b : scala.collection.Map[K,V2]) = {\n      for (k <- a.keySet) {\n        a(k) = cast(b.getOrElse(k, s2.zero));\n      }\n      for (k <- b.keySet) {\n        if (!a.contains(k)) {\n          a(k) = cast(b(k));\n        }\n      }\n    }\n  }\n\n  /** Set mutable map to cast scalar. */\n  implicit def OpSetMapScalarCast[K,V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Map[K,V1], V2, OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Map[K,V1], V2, OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Map[K,V1], b : V2) = {\n      val v = cast(b);\n      for (k <- a.keySet) {\n        a(k) = v;\n      }\n    }\n  }\n  \n  //\n  // Arrays\n  //\n  \n  /** Set array with casted values from another array. */\n  implicit def OpSetArrayArrayCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[Array[V1],Array[V2], OpSet]\n  = new BinaryUpdateOp[Array[V1],Array[V2], OpSet] {\n    def opType = OpSet;\n    def apply(a : Array[V1], b : Array[V2]) = {\n      var i = 0;\n      while (i < a.length) {\n        a(i) = cast(b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set array with casted scalar. */\n  implicit def OpSetArrayScalarCast[V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[Array[V1],V2,OpSet]\n  = new BinaryUpdateOp[Array[V1],V2,OpSet] {\n    def opType = OpSet;\n    def apply(a : Array[V1], b : V2) = { \n      val v = cast(b);\n      var i = 0;\n      while (i < a.length) {\n        a(i) = v;\n        i += 1;\n      }\n    }\n  }\n}\n\n/**\n * Low priority implicits.\n *\n * @author dramage\n */\ntrait BinaryUpdateOpImplicitsLevel1 extends BinaryUpdateOpImplicitsLevel0 {\n  \n  //\n  // Seqs\n  //\n  \n  /** Update mutable seq with corresponding values from another seq. */\n  implicit def OpUpdateSeqSeq[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[scala.collection.mutable.Seq[V1], scala.collection.Seq[V2], O]\n  = new BinaryUpdateOp[scala.collection.mutable.Seq[V1], scala.collection.Seq[V2], O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.mutable.Seq[V1], b : scala.collection.Seq[V2]) = {\n      require(a.size == b.size, \"Inputs must be the same length\");\n      var i = 0;\n      for (v <- b) {\n        a(i) = op(a(i),v);\n        i += 1;\n      }\n    }\n  }\n\n  /** Set mutable seq with corresponding value from another seq. */  \n  implicit def OpSetSeqSeq[V](implicit s : Scalar[V])\n  : BinaryUpdateOp[scala.collection.mutable.Seq[V], scala.collection.Seq[V], OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Seq[V], scala.collection.Seq[V], OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Seq[V], b : scala.collection.Seq[V]) = {\n      require(a.size == b.size, \"Inputs must be the same length\");\n      var i = 0;\n      for (v <- b) {\n        a(i) = v;\n        i += 1;\n      }\n    }\n  }\n  \n  /** Update mutable seq with scalar. */\n  implicit def OpUpdateSeqScalar[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], s : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Seq[V1], V2, O]\n  = new BinaryUpdateOp[scala.collection.mutable.Seq[V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.mutable.Seq[V1], b : V2) = {\n      var i = 0;\n      for (v <- a) {\n        a(i) = op(v,b);\n        i += 1;\n      }\n    }\n  }\n\n  /** Set mutable seq with scalar. */\n  implicit def OpSetSeqScalar[V](implicit s : Scalar[V])\n  : BinaryUpdateOp[scala.collection.mutable.Seq[V], V, OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Seq[V], V, OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Seq[V], b : V) = {\n      var i = 0;\n      while (i < a.length) {\n        a(i) = b;\n        i += 1;\n      }\n    }\n  }\n  \n  \n  //\n  // Maps\n  //\n  \n  /** Update mutable map with corresponding values from another map. */\n  implicit def OpUpdateMapMap[K,V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Map[K,V1], scala.collection.Map[K,V2], O]\n  = new BinaryUpdateOp[scala.collection.mutable.Map[K,V1], scala.collection.Map[K,V2], O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.mutable.Map[K,V1], b : scala.collection.Map[K,V2]) = {\n      for (k <- a.keySet) {\n        a(k) = op(a(k), b.getOrElse(k,s2.zero));\n      }\n      for (k <- b.keySet) {\n        if (!a.contains(k)) {\n          a(k) = op(s1.zero, b(k));\n        }\n      }\n    }\n  }\n\n  /** Set contents of mutable map with corresponding values from another map. */\n  implicit def OpSetMapMap[K,V](implicit s : Scalar[V])\n  : BinaryUpdateOp[scala.collection.mutable.Map[K,V], scala.collection.Map[K,V], OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Map[K,V], scala.collection.Map[K,V], OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Map[K,V], b : scala.collection.Map[K,V]) = {\n      for (k <- a.keySet) {\n        a(k) = b.getOrElse(k,s.zero);\n      }\n      for (k <- b.keySet) {\n        if (!a.contains(k)) {\n          a(k) = b(k);\n        }\n      }\n    }\n  }\n  \n  /** Update mutable map with scalar. */\n  implicit def OpUpdateMapScalar[K,V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], s : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.mutable.Map[K,V1], V2, O]\n  = new BinaryUpdateOp[scala.collection.mutable.Map[K,V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.mutable.Map[K,V1], b : V2) =\n      a.transform((k,v) => op(v, b));\n  }\n\n  /** Set mutable map to scalar. */\n  implicit def OpSetMapScalar[K,V](implicit s : Scalar[V])\n  : BinaryUpdateOp[scala.collection.mutable.Map[K,V], V, OpSet]\n  = new BinaryUpdateOp[scala.collection.mutable.Map[K,V], V, OpSet] {\n    def opType = OpSet;\n    def apply(a : scala.collection.mutable.Map[K,V], b : V) = {\n      for (k <- a.keySet) {\n        a(k) = b;\n      }\n    }\n  }\n  \n  //\n  // Arrays\n  //\n  \n  /** Update array with corresponding values from another array. */\n  implicit def OpUpdateArrayArray[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[Array[V1], Array[V2], O]\n  = new BinaryUpdateOp[Array[V1], Array[V2], O] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        a(i) = op(a(i),b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set array with corresponding values from another array. */\n  implicit def OpSetArrayArray[V](implicit s : Scalar[V])\n  : BinaryUpdateOp[Array[V],Array[V],OpSet]\n  = new BinaryUpdateOp[Array[V],Array[V],OpSet] {\n    def opType = OpSet;\n    def apply(a : Array[V], b : Array[V]) = { \n      require(a.length == b.length, \"Inputs must be the same length\");\n      System.arraycopy(b, 0, a, 0, a.length);\n    }\n  }\n  \n  /** Update array with scalar. */\n  implicit def OpUpdateArrayScalar[V1,V2,O<:OpType]\n  (implicit op : BinaryOp[V1,V2,O,V1], s : Scalar[V2])\n  : BinaryUpdateOp[Array[V1], V2, O]\n  = new BinaryUpdateOp[Array[V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : V2) = {\n      var i = 0;\n      while (i < a.length) {\n        a(i) = op(a(i),b);\n        i += 1;\n      }\n    }\n  }\n  \n  /** Set array with scalar. */\n  implicit def OpSetArrayScalar[V](implicit s : Scalar[V])\n  : BinaryUpdateOp[Array[V],V,OpSet]\n  = new BinaryUpdateOp[Array[V],V,OpSet] {\n    def opType = OpSet;\n    def apply(a : Array[V], b : V) = { \n      var i = 0;\n      while (i < a.length) {\n        a(i) = b;\n        i += 1;\n      }\n    }\n  }\n}\n\nobject BinaryUpdateOp extends BinaryUpdateOpImplicitsLevel1 {\n  \n  //\n  // Tuples\n  //\n  \n  implicit def OpRecurseTuple2Tuple2[VA1,VA2,VB1,VB2,O<:OpType]\n  (implicit op1 : BinaryUpdateOp[VA1,VB1,O], op2 : BinaryUpdateOp[VA2,VB2,O],\n   c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2])\n  : BinaryUpdateOp[(VA1,VA2), (VB1,VB2), O]\n  = new BinaryUpdateOp[(VA1,VA2), (VB1,VB2), O] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2), b : (VB1,VB2)) = {\n      op1(a._1,b._1);\n      op2(a._2,b._2);\n    }\n  }\n  \n  implicit def OpRecurseTuple2Scalar[VA1,VA2,VB,O<:OpType]\n  (implicit op1 : BinaryUpdateOp[VA1,VB,O], op2 : BinaryUpdateOp[VA2,VB,O],\n   s : Scalar[VB])\n  : BinaryUpdateOp[(VA1,VA2), VB, O]\n  = new BinaryUpdateOp[(VA1,VA2), VB, O] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2), b : VB) = {\n      op1(a._1,b);\n      op2(a._2,b);\n    }\n  }\n  \n  //\n  // Seqs\n  //\n  \n  /** Recurse on elements within a generic seq. */\n  implicit def OpRecurseSeqSeq[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[scala.collection.Seq[V1], scala.collection.Seq[V2], O]\n  = new BinaryUpdateOp[scala.collection.Seq[V1], scala.collection.Seq[V2], O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.Seq[V1], b : scala.collection.Seq[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      for ((av,bv) <- (a.iterator zip b.iterator)) {\n        op(av,bv);\n      }\n    }\n  }\n  \n  /** Recurse on elements within a generic seq. */\n  implicit def OpRecurseSeqScalar[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], s : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.Seq[V1], V2, O]\n  = new BinaryUpdateOp[scala.collection.Seq[V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.Seq[V1], b : V2) = {\n      for (v <- a) {\n        op(v, b);\n      }\n    }\n  }\n  \n  \n  //\n  // Maps\n  //\n  \n  /** Recurse on elements within a generic map. */\n  implicit def OpRecurseMapMap[K,V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[scala.collection.Map[K,V1], scala.collection.Map[K,V2], O]\n  = new BinaryUpdateOp[scala.collection.Map[K,V1], scala.collection.Map[K,V2], O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.Map[K,V1], b : scala.collection.Map[K,V2]) = {\n      for (k <- a.keySet) {\n        op(a(k),b(k));\n      }\n      for (k <- b.keySet) {\n        if (!a.keySet.contains(k)) {\n          op(a(k),b(k));\n        }\n      }\n    }\n  }\n  \n  /** Recurse on elements within a generic map. */\n  implicit def OpRecurseMapScalar[K,V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], s : Scalar[V2])\n  : BinaryUpdateOp[scala.collection.Map[K,V1], V2, O]\n  = new BinaryUpdateOp[scala.collection.Map[K,V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : scala.collection.Map[K,V1], b : V2) = {\n      for (v <- a.values) {\n        op(v,b);\n      }\n    }\n  }\n  \n  \n  //\n  // Arrays\n  //\n  \n  /** Recurse on elements within an array. */\n  implicit def OpRecurseArrayArray[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])\n  : BinaryUpdateOp[Array[V1], Array[V2], O]\n  = new BinaryUpdateOp[Array[V1], Array[V2], O] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : Array[V2]) = {\n      require(a.length == b.length, \"Inputs must be the same length\");\n      var i = 0;\n      while (i < a.length) {\n        op(a(i),b(i));\n        i += 1;\n      }\n    }\n  }\n  \n  implicit def OpRecurseArrayScalar[V1,V2,O<:OpType]\n  (implicit op : BinaryUpdateOp[V1,V2,O], s : Scalar[V2])\n  : BinaryUpdateOp[Array[V1], V2, O]\n  = new BinaryUpdateOp[Array[V1], V2, O] {\n    def opType = op.opType;\n    def apply(a : Array[V1], b : V2) = {\n      var i = 0;\n      while (i < a.length) {\n        op(a(i),b);\n        i += 1;\n      }\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/CanCast.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scala.annotation.implicitNotFound;\n\n/**\n * Cast a value from type A to B.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"Could not cast ${A} to ${B}\")\ntrait CanCast[-A,+B] extends (A => B);\n\nobject CanCast {\n  implicit object CanCastII extends CanCast[Int,Int]\n    { override def apply(v : Int) = v; }\n\n  implicit object CanCastIL extends CanCast[Int,Long]\n    { override def apply(v : Int) = v; }\n\n  implicit object CanCastIF extends CanCast[Int,Float]\n    { override def apply(v : Int) = v; }\n\n  implicit object CanCastID extends CanCast[Int,Double]\n    { override def apply(v : Int) = v; }\n\n  implicit object CanCastLL extends CanCast[Long,Long]\n    { override def apply(v : Long) = v; }\n\n  implicit object CanCastLD extends CanCast[Long,Double]\n    { override def apply(v : Long) = v; }\n\n  implicit object CanCastFF extends CanCast[Float,Float]\n    { override def apply(v : Float) = v; }\n\n  implicit object CanCastFD extends CanCast[Float,Double]\n    { override def apply(v : Float) = v; }\n\n  implicit object CanCastDD extends CanCast[Double,Double]\n    { override def apply(v : Double) = v; }\n\n  object CanCastIdentityAnyRef extends CanCast[AnyRef,AnyRef]\n    { override def apply(v : AnyRef) = v; }\n\n  implicit def CanCastIdentity[V] : CanCast[V,V] = \n    CanCastIdentity.asInstanceOf[CanCast[V,V]];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/OpType.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scalala.scalar.Scalar;\n\n/**\n * Marker trait for some operation, be it UnaryOp, BinaryOp, or\n * BinaryUpdateOp.\n *\n * @author dramage\n */\ntrait OpType;\n\n/**\n * Type marker for BinaryOp A :+ B and BinaryUpdateOp A :+= B.\n *\n * @author dramage\n */\ntrait OpAdd extends OpType;\nobject OpAdd extends OpAdd;\n\n/**\n * Type marker for BinaryOp A :- B and BinaryUpdateOp A :-= B.\n *\n * @author dramage\n */\ntrait OpSub extends OpType;\nobject OpSub extends OpSub;\n\n/**\n * Type marker for BinaryOp A :* B and BinaryUpdateOp A :*= B.\n *\n * @author dramage\n */\ntrait OpMul extends OpType;\nobject OpMul extends OpMul;\n\n/**\n * Type marker for BinaryOp A :/ B and BinaryUpdateOp A:/= B.\n *\n * @author dramage\n */\ntrait OpDiv extends OpType;\nobject OpDiv extends OpDiv;\n\n/**\n * Type marker for BinaryOp A :% B and BinaryUpdateOp A:%= B.\n *\n * @author dramage\n */\ntrait OpMod extends OpType;\nobject OpMod extends OpMod;\n\n/**\n * Type marker for BinaryOp A :^ B and BinaryUpdateOp A:^= B.\n *\n * @author dramage\n */\ntrait OpPow extends OpType;\nobject OpPow extends OpPow;\n\n/**\n * Type marker for BinaryOp A :&lt; B.\n *\n * @author dramage\n */\ntrait OpLT  extends OpType;\nobject OpLT  extends OpLT;\n\n/**\n * Type marker for BinaryOp A :&lt;= B.\n *\n * @author dramage\n */\ntrait OpLTE extends OpType;\nobject OpLTE extends OpLTE;\n\n/**\n * Type marker for BinaryOp A :&gt; B.\n *\n * @author dramage\n */\ntrait OpGT  extends OpType;\nobject OpGT  extends OpGT;\n\n/**\n * Type marker for BinaryOp A :&gt;= B.\n *\n * @author dramage\n */\ntrait OpGTE extends OpType;\nobject OpGTE extends OpGTE;\n\n/**\n * Type marker for BinaryOp A :== B.\n *\n * @author dramage\n */\ntrait OpEq  extends OpType;\nobject OpEq  extends OpEq;\n\n/**\n * Type marker for BinaryOp A :!= B.\n *\n * @author dramage\n */\ntrait OpNe  extends OpType;\nobject OpNe  extends OpNe;\n\n/**\n * Type marker for BinaryUpdateOp A := B.\n *\n * @author dramage\n */\ntrait OpSet extends OpType;\nobject OpSet extends OpSet;\n\n/**\n * Type marker for BinaryOp A :&& B\n *\n * @author dramage\n */\ntrait OpAnd extends OpType;\nobject OpAnd extends OpAnd;\n\n/**\n * Type marker for BinaryOp A :|| B\n *\n * @author dramage\n */\ntrait OpOr extends OpType;\nobject OpOr extends OpOr;\n\n/**\n * Type marker for BinaryOp A :^^ B\n *\n * @author dramage\n */\ntrait OpXor extends OpType;\nobject OpXor extends OpXor;\n\n/**\n * Type marker for UnaryOp -A.\n *\n * @author dramage\n */\ntrait OpNeg extends OpType;\nobject OpNeg extends OpNeg;\n\n/**\n * Type marker for UnaryOp !A.\n *\n * @author dramage\n */\ntrait OpNot extends OpType;\nobject OpNot extends OpNot;\n\n\n/**\n * Type marker for inner (dot) product of A and B.\n *\n * @author dramage\n */\ntrait OpMulInner extends OpType;\nobject OpMulInner extends OpMulInner;\n\n/**\n * Type marker for BinaryOp A * B when A is a row.\n *\n * @author dramage\n */\ntrait OpMulRowVectorBy extends OpType;\nobject OpMulRowVectorBy extends OpMulRowVectorBy;\n\n/**\n * Type marker for BinaryOp A * B when A is a column.\n *\n * @author dramage\n */\ntrait OpMulColVectorBy extends OpType;\nobject OpMulColVectorBy extends OpMulColVectorBy;\n\n/**\n * Type marker for BinaryOp A * B when A is a matrix.\n *\n * @author dramage\n */\ntrait OpMulMatrixBy extends OpType;\nobject OpMulMatrixBy extends OpMulMatrixBy;\n\n/**\n * Type marker for BinaryOp A \\ B when A is a matrix.\n *\n * @author dramage\n */\ntrait OpSolveMatrixBy extends OpType;\nobject OpSolveMatrixBy extends OpSolveMatrixBy;\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/Ops.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scalala.scalar.Scalar;\nimport scalala.collection.sparse.{SparseArray,DefaultArrayValue};\n\n/**\n * Mix-in trait for supporting numeric operators on instances of type This\n * (accessible with the repr method).\n *\n * @author dramage\n */\ntrait NumericOps[+This] {\n  def repr : This;\n\n  def unary_-[TT>:This,That](implicit op : UnaryOp[TT,OpNeg,That]) = op(repr);\n\n  def unary_![TT>:This,That](implicit op : UnaryOp[TT,OpNot,That]) = op(repr);\n\n  /** Element-wise sum of this and b. */\n  def :+ [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAdd,That]) = op(repr,b);\n  \n  /** Returns the operator delegate used in :+ */\n  def :+?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAdd,That]) = op;\n\n  /** Element-wise difference of this and b. */\n  def :- [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpSub,That]) = op(repr,b);\n  \n  /** Returns the operator delegate used in :- */\n  def :-?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpSub,That]) = op;\n\n  /** Element-wise product of this and b. */\n  def :* [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMul,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :* */\n  def :*?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMul,That]) = op;\n\n  /** Element-wise quotient of this and b. */\n  def :/ [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpDiv,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :/ */\n  def :/?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpDiv,That]) = op;\n\n  /** Element-wise modulo of this and b. */\n  def :% [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMod,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :% */\n  def :%?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMod,That]) = op;\n\n  /** Element-wise exponentiation of this and b. */\n  def :^ [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpPow,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :^ */\n  def :^?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpPow,That]) = op;\n\n  /** Element-wise less=than comparator of this and b. */\n  def :< [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpLT,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :< */\n  def :<?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpLT,That]) = op;\n\n  /** Element-wise less-than-or-equal-to comparator of this and b. */\n  def :<= [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpLTE,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :<= */\n  def :<=?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpLTE,That]) = op;\n\n  /** Element-wise greater-than comparator of this and b. */\n  def :> [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpGT,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :> */\n  def :>?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpGT,That]) = op;\n\n  /** Element-wise greater-than-or-equal-to comparator of this and b. */\n  def :>= [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpGTE,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :>= */\n  def :>=?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpGTE,That]) = op;\n\n  /** Element-wise equality comparator of this and b. */\n  def :== [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpEq,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :== */\n  def :==?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpEq,That]) = op;\n\n  /** Element-wise inequality comparator of this and b. */\n  def :!= [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpNe,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :!= */\n  def :!=?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpNe,That]) = op;\n\n  /** Element-wise logical \"and\" operator -- returns true if corresponding elements are non-zero. */\n  def :&& [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAnd,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :&& */\n  def :&&?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAnd,That]) = op;\n\n  /** Element-wise logical \"or\" operator -- returns true if either element is non-zero. */\n  def :|| [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpOr,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :|| */\n  def :||?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpOr,That]) = op;\n\n  /** Element-wise logical \"xor\" operator -- returns true if only one of the corresponding elements is non-zero. */\n  def :^^ [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpXor,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in :^^ */\n  def :^^?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpXor,That]) = op;\n\n  /** Inner product of this and b. */\n  def dot [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulInner,That]) = op(repr,b);\n\n  /** Returns the operator delegate used in dot */\n  def dotOp[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulInner,That]) = op;\n\n  //\n  // Operator aliases\n  //\n\n  /** Alias for :+(b) for all b. */\n  final def + [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAdd,That]) = this.:+(b);\n\n  /** Returns the operator delegate used in + */\n  final def +?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAdd,That]) = op;\n\n  /** Alias for :-(b) for all b. */\n  final def - [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpSub,That]) = this.:-(b);\n\n  /** Returns the operator delegate used in - */\n  final def -?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpSub,That]) = op;\n\n  /** Alias for :*(b) when b is a scalar. */\n  final def * [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMul,That], sb : Scalar[B]) = this.:*(b);\n\n  /** Returns the operator delegate used in * */\n  final def *?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMul,That], sb : Scalar[B]) = op;\n\n  /** Alias for :/(b) when b is a scalar. */\n  final def / [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpDiv,That], sb : Scalar[B]) = this.:/(b);\n\n  /** Returns the operator delegate used in / */\n  final def /?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpDiv,That], sb : Scalar[B]) = op;\n\n  /** Alias for :%(b) when b is a scalar. */\n  final def % [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMod,That], sb : Scalar[B]) = this.:%(b);\n\n  /** Returns the operator delegate used in % */\n  final def %?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMod,That], sb : Scalar[B]) = op;\n  \n  /** Alias for :&&(b) for all b. */\n  final def && [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAnd,That]) = this.:&&(b);\n\n  /** Returns the operator delegate used in && */\n  final def &&?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpAnd,That]) = op;\n  \n  /** Alias for :||(b) for all b. */\n  final def || [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpOr,That]) = this.:||(b);\n\n  /** Returns the operator delegate used in || */\n  final def ||?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpOr,That]) = op;\n  \n  /** Alias for :^^(b) for all b. */\n  final def ^^ [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpXor,That]) = this.:^^(b);\n\n  /** Returns the operator delegate used in ^^ */\n  final def ^^?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpXor,That]) = op;\n}\n\n/**\n * Operators for mutable numeric collections.\n *\n * @author dramage\n */\ntrait MutableNumericOps[+This] extends NumericOps[This] {\n  def repr : This;\n\n  /** Mutates this by element-wise assignment of b into this. */\n  def := [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpSet]) : This = {\n    op(repr,b);\n    return repr;\n  }\n  \n  /** Returns the operator delegate used in := */\n  def :=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpSet]) = op;\n  \n  /** Mutates this by element-wise addition of b into this. */\n  def :+= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpAdd]) : This = {\n    op(repr,b);\n    return repr;\n  }\n\n  /** Returns the operator delegate used in :+= */\n  def :+=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpAdd]) = op;\n\n  /** Mutates this by element-wise subtraction of b from this */\n  def :-= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpSub]) : This = {\n    op(repr,b);\n    return repr;\n  }\n\n  /** Returns the operator delegate used in :-= */\n  def :-=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpSub]) = op;\n\n  /** Mutates this by element-wise multiplication of b into this. */\n  def :*= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMul]) : This = {\n    op(repr,b);\n    return repr;\n  }\n\n  /** Returns the operator delegate used in :*= */\n  def :*=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMul]) = op;\n\n  /** Mutates this by element-wise division of b into this */\n  def :/= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpDiv]) : This = {\n    op(repr,b);\n    return repr;\n  }\n\n  /** Returns the operator delegate used in :/= */\n  def :/=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpDiv]) = op;\n\n  /** Mutates this by element-wise modulo of b into this. */\n  def :%= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMod]) : This = {\n    op(repr,b);\n    return repr;\n  }\n\n  /** Returns the operator delegate used in :%= */\n  def :%=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMod]) = op;\n\n  /** Mutates this by element-wise exponentiation of this by b. */\n  def :^= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpPow]) : This = {\n    op(repr,b);\n    return repr;\n  }\n\n  /** Returns the operator delegate used in :^= */\n  def :^=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpPow]) = op;\n\n  /** Alias for :+=(b) for all b. */\n  final def += [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpAdd]) =\n    this.:+=[TT,B](b);\n\n  /** Returns the operator delegate used in += */\n  final def +=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpAdd]) = op;\n\n  /** Alias for :-=(b) for all b. */\n  final def -= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpSub]) =\n    this.:-=[TT,B](b);\n\n  /** Returns the operator delegate used in -= */\n  final def -=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpSub]) = op;\n\n  /** Alias for :*=(b) when b is a scalar. */\n  final def *= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMul], sb : Scalar[B]) =\n    this.:*=[TT,B](b);\n\n  /** Returns the operator delegate used in *= */\n  final def *=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMul], sb : Scalar[B]) = op;\n\n  /** Alias for :/=(b) when b is a scalar. */\n  final def /= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpDiv], sb : Scalar[B]) =\n    this.:/=[TT,B](b);\n\n  /** Returns the operator delegate used in /= */\n  final def /=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpDiv], sb : Scalar[B]) = op;\n\n  /** Alias for :%=(b) when b is a scalar. */\n  final def %= [TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMod], sb : Scalar[B]) =\n    this.:%=[TT,B](b);\n    \n  /** Returns the operator delegate used in %= */\n  final def %=?[TT>:This,B](b : B)(implicit op : BinaryUpdateOp[TT,B,OpMod], sb : Scalar[B]) = op;\n}\n\n//\n// Shaped operations\n// \n\n/**\n * Secialized shaped numeric operations for columns.\n *\n * @author dramage\n */\ntrait ColOps[+This] extends NumericOps[This] {\n  /** Shaped multiplication of this by b. */\n  def * [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulColVectorBy,That]) : That =\n    op(repr, b);\n\n  /** Returns the operator delegate used in * */\n  def *?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulColVectorBy,That]) = op;\n\n  /** A transposed view of this column. */\n  def t [TT>:This,That](implicit op : CanTranspose[TT,That]) =\n    op.apply(repr);\n\n  /** Returns the operator delegate used in t */\n  def tOp[TT>:This,That](implicit op : CanTranspose[TT,That]) = op;\n}\n\n\n/**\n * Secialized shaped numeric operations for rows.\n *\n * @author dramage\n */\ntrait RowOps[+This] extends NumericOps[This] {\n  /** Shaped multiplication of this by b. */\n  def * [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulRowVectorBy,That]) : That =\n    op(repr, b);\n    \n  /** Returns the operator delegate used in * */\n  def *?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulRowVectorBy,That]) = op;\n\n  /** A transposed view of this column. */\n  def t [TT>:This,That](implicit op : CanTranspose[TT,That]) =\n    op.apply(repr);\n  \n  /** Returns the operator delegate used in t */\n  def tOp[TT>:This,That](implicit op : CanTranspose[TT,That]) = op;\n}\n\n/**\n * Provides matrix-like operations for two dimensional collections.\n *\n * @author dramage\n */\ntrait MatrixOps[+This] extends NumericOps[This] {\n  /** Shaped multiplication of this by b. */\n  def * [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulMatrixBy,That]) =\n    op.apply(repr,b);\n\n  /** Returns the operator delegate used in * */\n  def *?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulMatrixBy,That]) = op;\n\n  /** Shaped solve of this by b. */\n  def \\ [TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpSolveMatrixBy,That]) =\n    op.apply(repr,b);\n\n  /** Returns the operator delegate used in \\ */\n  def \\?[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpSolveMatrixBy,That]) = op;\n\n  /** A transposed view of this matrix. */\n  def t [TT>:This,That](implicit op : CanTranspose[TT,That]) =\n    op.apply(repr);\n    \n  /** Returns the operator delegate used in t */\n  def tOp[TT>:This,That](implicit op : CanTranspose[TT,That]) = op;\n}\n\n// /**\n//  * Specialized column and row tensor ops for wrapped data structures that\n//  * cannot directly inherit and distinguish between rows and columns in the\n//  * type system.  This class assumes unwrapped objects are columns and\n//  * wrapped ones are rows.\n//  *\n//  * @author dramage\n//  */\n// trait WrappedColOps[+This] extends NumericOps[This] {\n//   def *[TT>:This,B,That](b : WrappedRowOps[B])(implicit op : BinaryOp[TT,B,OpMulColVectorBy,That]) : That =\n//     op(repr,b.column);\n// \n//   def t : WrappedRowOps[This] = WrappedRowOps(repr);\n// }\n// \n// /**\n//  * A wrapped column tensor whose underyling collection is mutable.  This trait\n//  * should be used instead of mixing in \"WrappedColOps with\n//  * MutableNumeriCollectionOps\" directly, because .t needs to return an instance\n//  * of MutableRowOps insetad of RowOps.\n//  *\n//  * @author dramage\n//  */\n// trait MutableWrappedColOps[+This] extends WrappedColOps[This] with MutableNumericOps[This] {\n//   override def t : MutableWrappedRowOps[This] = MutableWrappedRowOps(repr);\n// }\n// \n// /**\n//  * Secialized NumericOps with shaped operations taking A is a row.\n//  * Note that there is an inherent asymmetry between WrappedColumnTensorOps and\n//  * WrappedRowOps: because tensors are assumed to be columns until reshaped\n//  * (e.g. by calling .t), that class extends NumericOps[A].  This\n//  * class, by contrast, must preserve the fact that the base numeric operations\n//  * like plus must honor the row shape, and that the return result should also\n//  * be a row.  Hence this class extends NumericOps[WrappedRowOps[A]]\n//  * and provides implicit magic in the companion object to wrap the\n//  * corresponding construction delegates.\n//  *\n//  * @author dramage\n//  */\n// trait WrappedRowOps[+This] extends NumericOps[WrappedRowOps[This]] {\n//   override def repr : WrappedRowOps[This] = this;\n// \n//   def column : This;\n// \n//   def *[TT>:This,B,That](b : B)(implicit op : BinaryOp[TT,B,OpMulRowVectorBy,That]) : That =\n//     op(this.column,b);\n// \n//   /** The transpose returns the underlying value, which assumed to be a column. */\n//   def t : This = column;\n// }\n// \n// object WrappedRowOps {\n//   def apply[This](v : This) : WrappedRowOps[This] =\n//     new WrappedRowOps[This] { override def column = v; }\n// \n//   class WrappedRowBinaryOp[A,-B,Op<:OpType,+That](implicit op : BinaryOp[A,B,Op,That])\n//   extends BinaryOp[WrappedRowOps[A],WrappedRowOps[B],Op,WrappedRowOps[That]] {\n//     override def apply(a : WrappedRowOps[A], b : WrappedRowOps[B]) =\n//       WrappedRowOps(op(a.column,b.column));\n//   }\n// \n//   implicit def unwrap[A,B,Op<:OpType,That](implicit op : BinaryOp[A,B,Op,That])\n//   = new WrappedRowBinaryOp[A,B,Op,That];\n// }\n// \n// /**\n//  * Specialized WrappedRowOps support for WrappedRows that have mutable\n//  * underlying collections.\n//  *\n//  * @author dramage\n//  */\n// trait MutableWrappedRowOps[+This]\n// extends WrappedRowOps[This] with MutableNumericOps[WrappedRowOps[This]];\n// \n// object MutableWrappedRowOps {\n//   def apply[This](v : This) : MutableWrappedRowOps[This] =\n//     new MutableWrappedRowOps[This] { override def column = v; }\n// \n//   class MutableWrappedRowBinaryOp[A,-B,Op<:OpType,+That](implicit op : BinaryOp[A,B,Op,That])\n//   extends BinaryOp[MutableWrappedRowOps[A],WrappedRowOps[B],Op,MutableWrappedRowOps[That]] {\n//     override def apply(a : MutableWrappedRowOps[A], b : WrappedRowOps[B]) =\n//       MutableWrappedRowOps(op(a.column,b.column));\n//   }\n// \n//   class MutableWrappedRowBinaryUpdateOp[A,-B,Op<:OpType](implicit op : BinaryUpdateOp[A,B,Op])\n//   extends BinaryUpdateOp[MutableWrappedRowOps[A],WrappedRowOps[B],Op] {\n//     override def apply(a : MutableWrappedRowOps[A], b : WrappedRowOps[B]) =\n//       op(a.column, b.column);\n//   }\n// \n//   implicit def unwrapBinaryOp[A,B,Op<:OpType,That](implicit op : BinaryOp[A,B,Op,That])\n//   = new MutableWrappedRowBinaryOp[A,B,Op,That];\n// \n//   implicit def unwrapBinaryUpdateOp[A,B,Op<:OpType](implicit op : BinaryUpdateOp[A,B,Op])\n//   = new MutableWrappedRowBinaryUpdateOp[A,B,Op];\n// }\n\n/**\n * Numeric operator support for numeric arrays.\n *\n * @author dramage\n */\nclass RichArrayVector[V:ClassManifest](override val repr : Array[V])\nextends MutableNumericOps[Array[V]] {\n//extends MutableWrappedColOps[Array[V]] {\n\n  /** Returns a vector view of this array. */\n  def asVector(implicit s : Scalar[V]) = new scalala.tensor.dense.DenseVectorCol(repr);\n}\n\n/**\n * Numeric operator support for Array[Array] matrix.\n * \n * @author dramage\n */\nclass RichArrayMatrix[V:ClassManifest](override val repr : Array[Array[V]])\nextends MutableNumericOps[Array[Array[V]]] {\n//extends MatrixOps[Array[Array[V]]] {\n\n  /** Returns a matrix view of this array. */\n  def asMatrix(implicit s : Scalar[V]) = new scalala.tensor.dense.ArrayArrayMatrix(repr);\n}\n\n/**\n * Numeric operator support for SparseArray vector.\n *\n * @author dramage\n */\nclass RichSparseArrayVector[V:ClassManifest:DefaultArrayValue](override val repr : SparseArray[V])\nextends MutableNumericOps[SparseArray[V]] {\n//extends MutableWrappedColOps[SparseArray[V]] {\n\n  /** Returns a vector view of this sparse array. */\n  def asVector(implicit s : Scalar[V]) = new scalala.tensor.sparse.SparseVectorCol(repr);\n}\n\n/**\n * Numeric operator support for solo scalars.  Note: raw + is ambiguous\n * with the any2String implicit that comes built in with scala and is used\n   for string concatenation.  Use :+ instead.\n *\n * @author dramage\n */\nclass RichScalar[@specialized V:Scalar](override val repr : V)\nextends NumericOps[V] {\n  /** This is a scalar, so alias for :*(b) for all b. */\n  final def *[B,That](b : B)(implicit op : BinaryOp[V,B,OpMul,That]) =\n    this.:*(b);\n\n  /** This is a scalar, so alias for :/(b) for all b. */\n  final def /[B,That](b : B)(implicit op : BinaryOp[V,B,OpDiv,That]) =\n    this.:/(b);\n\n  /** This is a scalar, so alias for :%(b) for all b. */\n  final def %[B,That](b : B)(implicit op : BinaryOp[V,B,OpMod,That]) =\n    this.:%(b);\n}\n\n/**\n * Adds rich math operators to a map.  Adds mutable as well as\n * immutable operators because inner data structures may be mutable.\n *\n * @author dramage\n */\nclass RichMap[M<:scala.collection.Map[_,_]](override val repr : M)\nextends MutableNumericOps[M];\n\n/**\n * Adds rich math operators to a seq.  Adds mutable as well as\n * immutable operators because inner data structures may be mutable.\n *\n * @author dramage\n */\nclass RichSeq[S<:scala.collection.Seq[_]](override val repr : S)\nextends MutableNumericOps[S] {\n//  TODO: add me when we can reliably get the value type from the collection\n//\n//  /** Constructs a new vector view of this sequence. */\n//  def toVector(implicit s : Scalar[V]) = {\n//    implicit val mf = s.manifest;\n//    new RichArray(repr.toArray).asVector;\n//  }\n//\n//  /**\n//   * Constructs a new matrix view of this sequence.\n//   * If only one of rows or cols is specified, infers the other.\n//   */\n//  def toMatrix(rows : Int = -1, cols : Int = -1)(implicit s : Scalar[V]) = {\n//    implicit val mf = s.manifest;\n//    new RichArray(repr.toArray).asMatrix(rows, cols);\n//  }\n}\n\n/**\n * Adds rich math operators to an array.\n *\n * @author dramage\n */\nclass RichArray[@specialized V](override val repr : Array[V])\nextends MutableNumericOps[Array[V]] {\n  /** Constructs a view of this array as a column vector. */\n  def asVector(implicit s : Scalar[V]) =\n    new scalala.tensor.dense.DenseVectorCol(repr);\n    \n  /**\n   * Constructs a view of this array as a matrix of the given dimensions.\n   * If only one of rows or cols is specified, infers the other.\n   */\n  def asMatrix(rows : Int = -1, cols : Int = -1)(implicit s : Scalar[V]) = {\n    require(rows > 0 || cols > 0, \"Must specify either rows or cols to view as matrix.\");\n    val r = if (rows >= 0) rows else {\n      require(repr.length % cols == 0, \"Input length does not evenly divide by requested number of cols\");\n     repr.length / cols;\n    };\n    \n    val c = if (cols >= 0) cols else {\n      require(repr.length % rows == 0, \"Input length does not evenly divide by requested number of rows\");\n     repr.length / rows;\n    };\n    \n    new scalala.tensor.dense.DenseMatrix(r, c, repr);\n  }\n}\n\n/**\n * Adds rich math operators to functions.\n *\n * @author dramage\n */\nclass RichFunction2[@specialized A, @specialized B](override val repr : A=>B)\nextends NumericOps[A=>B] {\n  def :@[VV,That](values : VV)(implicit bf : scala.collection.generic.CanBuildFrom[VV,B,That], vv : VV => TraversableOnce[A]) = {\n    val rv = bf(values);\n    for (v <- values) rv += repr(v);\n    rv.result;\n  }\n}\n\ntrait ImplicitsLevel0 {\n  implicit def richScalar[@specialized V:Scalar](value : V) =\n    new RichScalar(value);\n}\n\ntrait ImplicitsLevel1 extends ImplicitsLevel0 {\n  implicit def richMap[M<:scala.collection.Map[_,_]](map : M) = new RichMap(map);\n  \n  implicit def richSeq[S<:scala.collection.Seq[_]](seq : S) = new RichSeq(seq);\n  \n  implicit def richArray[@specialized V:Scalar](arr : Array[V]) = new RichArray(arr);\n\n}\n\n/**\n * Implicit promotions of built-in scala types to enriched numerically valued\n * equivalents.  After importing the members of this class, you can directly\n * do math on all tuples, arrays, and maps.\n *\n * @author dramage\n */\nobject Implicits extends RichTupleImplicits with ImplicitsLevel1 {\n  implicit def richArrayMatrix[@specialized V:Scalar:ClassManifest](arr : Array[Array[V]]) = new RichArrayMatrix(arr);\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/Shape.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scala.annotation.implicitNotFound;\nimport scalala.scalar.Scalar;\n\n/**\n * Marker trait describing the shape of a value V as having\n * shape signature S.  This class is never instantiated and\n * is used only as an implicit to ensure compatibility between\n * shapes of arguments when operating on collections.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"Could not recover shape of ${V}\")\ntrait Shape[-V,S];\n\ntrait LowPriorityShapeImplicits {\n  /** Arbitrary objects have shape Unit. */\n  @inline implicit def any[V] : Shape[V,Unit] = null;\n}\n\nobject Shape extends LowPriorityShapeImplicits {\n  def apply[V,S](v : V)(implicit shape : Shape[V,S]) = shape;\n\n  /** Tuples have shape (Unit,Unit, ...). */\n  @inline implicit def tuple2[V1,V2]\n  : Shape[(V1,V2),(Unit,Unit)] = null;\n  \n  /** Tuples have shape (Unit,Unit, ...). */\n  @inline implicit def tuple3[V1,V2,V3]\n  : Shape[(V1,V2,V3),(Unit,Unit,Unit)] = null;\n  \n  /** Tuples have shape (Unit,Unit, ...). */\n  @inline implicit def tuple4[V1,V2,V3,V4]\n  : Shape[(V1,V2,V3,V4),(Unit,Unit,Unit,Unit)] = null;\n\n  // TODO: add more tuples\n  \n  /** Maps have shape (KeyShape=>ValueShape). */\n  @inline implicit def map[K,KeyShape,V,ValueShape]\n  (implicit kShape : Shape[K,KeyShape], vShape : Shape[V,ValueShape])\n  : Shape[scala.collection.Map[K,V],(KeyShape=>ValueShape)] = null;\n  \n  /** Seqs have shape (Unit=>ValueShape). */\n  @inline implicit def seq[V,ValueShape](implicit vShape : Shape[V,ValueShape])\n  : Shape[scala.collection.Seq[V],(Unit=>ValueShape)] = null;\n  \n  /** Arrays have shape (Unit=>ValueShape). */\n  @inline implicit def array[V,ValueShape](implicit vShape : Shape[V,ValueShape])\n  : Shape[Array[V],(Unit=>ValueShape)] = null;\n}\n\n/**\n * Marker trait that says that A and B have statically\n * compatible shape.  This trait is never instantiated and is\n * used only as an implicit to ensure that types A and B have\n * compatible shapes for performing operations.\n *\n * @author dramage \n */\n@implicitNotFound(msg=\"Types ${A} and ${B} have incompatible shape\")\nsealed trait CompatibleShape[A,B]\n\nobject CompatibleShape {\n  @inline implicit def apply[A,SA,B,SB]\n  (implicit sa : Shape[A,SA], sb : Shape[B,SB], eq : =:=[SA,SB])\n  : CompatibleShape[A,B] = null;\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/TupleOps.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scalala.scalar.Scalar;\n\n// The contents of this file were automatically generated:\n\n// println(\"trait UnaryTupleOps {\");\n// for (n <- 2 to 22) {\n//   val va = (1 to n).map(\"VA\"+_).mkString(\",\");\n//   val rv = (1 to n).map(\"RV\"+_).mkString(\",\");\n//   val ops = (1 to n).map(i => \"op! : UnaryOp[VA!,O,RV!]\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val code = (1 to n).map(i => \"op!(v._!)\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val unaryOp =\n// \"\"\"\n//   implicit def OpTuple%d[%s,%s,O<:OpType]\n//   (implicit %s)\n//   : UnaryOp[(%s),O,(%s)]\n//   = new UnaryOp[(%s),O,(%s)] {\n//     def opType = op1.opType;\n//     def apply(v : (%s)) = (%s);\n//   }\n// \"\"\".format(n,va,rv,ops,va,rv,va,rv,va,code);\n//   print(unaryOp);\n// }\n// println(\"}\");\n// \n// println(\"trait BinaryTupleOps {\");\n// for (n <- 2 to 22) {\n//   val va = (1 to n).map(\"VA\"+_).mkString(\",\");\n//   val vb = (1 to n).map(\"VB\"+_).mkString(\",\");\n//   val rv = (1 to n).map(\"RV\"+_).mkString(\",\");\n// \n//   val opsTupleTuple = (1 to n).map(i => \"op! : BinaryOp[VA!,VB!,O,RV!]\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val shapesTupleTuple = (1 to n).map(i => \"c! : CompatibleShape[VA!,VB!]\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val valueTupleTuple = (1 to n).map(i => \"op!(a._!,b._!)\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val codeTupleTuple =\n// \"\"\"\n//   implicit def OpTuple%dTuple%d[%s,%s,%s,O<:OpType]\n//   (implicit %s, %s)\n//   : BinaryOp[(%s),(%s),O,(%s)]\n//   = new BinaryOp[(%s),(%s),O,(%s)] {\n//     def opType = op1.opType;\n//     def apply(a : (%s), b : (%s)) = (%s);\n//   }\n// \"\"\".format(n, n, va, vb, rv, opsTupleTuple, shapesTupleTuple, va, vb, rv, va, vb, rv, va, vb, valueTupleTuple);\n// \n//   val opsTupleScalar = (1 to n).map(i => \"op! : BinaryOp[VA!,VS,O,RV!]\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val valueTupleScalar = (1 to n).map(i => \"op!(a._!,s)\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val codeTupleScalar =\n// \"\"\"\n//   implicit def OpTuple%dScalar[%s,VS,%s,O<:OpType]\n//   (implicit %s, s : Scalar[VS])\n//   : BinaryOp[(%s),VS,O,(%s)]\n//   = new BinaryOp[(%s),VS,O,(%s)] {\n//     def opType = op1.opType;\n//     def apply(a : (%s), s : VS) = (%s);\n//   }\n// \"\"\".format(n, va, rv, opsTupleScalar, va, rv, va, rv, va, valueTupleScalar);\n// \n//   val opsScalarTuple = (1 to n).map(i => \"op! : BinaryOp[VS,VB!,O,RV!]\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val valueScalarTuple = (1 to n).map(i => \"op!(s,b._!)\".replaceAll(\"!\",\"\"+i)).mkString(\", \");\n//   val codeScalarTuple =\n// \"\"\"\n//   implicit def OpScalarTuple%d[VS,%s,%s,O<:OpType]\n//   (implicit %s, s : Scalar[VS])\n//   : BinaryOp[VS,(%s),O,(%s)]\n//   = new BinaryOp[VS,(%s),O,(%s)] {\n//     def opType = op1.opType;\n//     def apply(s : VS, b : (%s)) = (%s);\n//   }\n// \"\"\".format(n, vb, rv, opsScalarTuple, vb, rv, vb, rv, vb, valueScalarTuple);\n// \n//   print(codeTupleTuple);\n//   print(codeTupleScalar);\n//   print(codeScalarTuple);\n// }\n// println(\"}\");\n// \n// println(\"object RichTuples {\");\n// for (n <- 2 to 22) {\n//   val tupArg = (1 to n).map((if (n <= 3) \"@specialized V\" else \"V\") + _).mkString(\", \");\n//   val tupVal = (1 to n).map(\"V\"+_).mkString(\",\");\n//   println(\n//     \"  class RichTuple%d[%s](override val repr : (%s)) extends MutableNumericOps[(%s)];\\n\"\n//       .format(n,tupArg,tupVal,tupVal)\n//   );\n// }\n// println(\"}\\n\\n\");\n// \n// println(\"trait RichTupleImplicits {\");\n// println(\"  import RichTuples._\");\n// for (n <- 2 to 22) {\n//   val tupArg = (1 to n).map((if (n <= 3) \"@specialized V\" else \"V\") + _).mkString(\", \");\n//   val tupVal = (1 to n).map(\"V\"+_).mkString(\",\");\n//   println(\n//     \"  implicit def richTuple%d[%s](value : (%s)) = new RichTuple%d(value);\\n\"\n//       .format(n,tupArg,tupVal,n)\n//   );\n// }\n// println(\"}\\n\");\n\n/**\n * Unary operations on tensors of arity 2 to 22.\n *\n * @author dramage\n */\ntrait UnaryTupleOps {\n\n  implicit def OpTuple2[VA1,VA2,RV1,RV2,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2])\n  : UnaryOp[(VA1,VA2),O,(RV1,RV2)]\n  = new UnaryOp[(VA1,VA2),O,(RV1,RV2)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2)) = (op1(v._1), op2(v._2));\n  }\n\n  implicit def OpTuple3[VA1,VA2,VA3,RV1,RV2,RV3,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3])\n  : UnaryOp[(VA1,VA2,VA3),O,(RV1,RV2,RV3)]\n  = new UnaryOp[(VA1,VA2,VA3),O,(RV1,RV2,RV3)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3)) = (op1(v._1), op2(v._2), op3(v._3));\n  }\n\n  implicit def OpTuple4[VA1,VA2,VA3,VA4,RV1,RV2,RV3,RV4,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4])\n  : UnaryOp[(VA1,VA2,VA3,VA4),O,(RV1,RV2,RV3,RV4)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4),O,(RV1,RV2,RV3,RV4)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4));\n  }\n\n  implicit def OpTuple5[VA1,VA2,VA3,VA4,VA5,RV1,RV2,RV3,RV4,RV5,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5),O,(RV1,RV2,RV3,RV4,RV5)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5),O,(RV1,RV2,RV3,RV4,RV5)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5));\n  }\n\n  implicit def OpTuple6[VA1,VA2,VA3,VA4,VA5,VA6,RV1,RV2,RV3,RV4,RV5,RV6,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6),O,(RV1,RV2,RV3,RV4,RV5,RV6)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6),O,(RV1,RV2,RV3,RV4,RV5,RV6)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6));\n  }\n\n  implicit def OpTuple7[VA1,VA2,VA3,VA4,VA5,VA6,VA7,RV1,RV2,RV3,RV4,RV5,RV6,RV7,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7));\n  }\n\n  implicit def OpTuple8[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8));\n  }\n\n  implicit def OpTuple9[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9));\n  }\n\n  implicit def OpTuple10[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10));\n  }\n\n  implicit def OpTuple11[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11));\n  }\n\n  implicit def OpTuple12[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12));\n  }\n\n  implicit def OpTuple13[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13));\n  }\n\n  implicit def OpTuple14[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14));\n  }\n\n  implicit def OpTuple15[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15));\n  }\n\n  implicit def OpTuple16[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16));\n  }\n\n  implicit def OpTuple17[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16], op17 : UnaryOp[VA17,O,RV17])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16), op17(v._17));\n  }\n\n  implicit def OpTuple18[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16], op17 : UnaryOp[VA17,O,RV17], op18 : UnaryOp[VA18,O,RV18])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16), op17(v._17), op18(v._18));\n  }\n\n  implicit def OpTuple19[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16], op17 : UnaryOp[VA17,O,RV17], op18 : UnaryOp[VA18,O,RV18], op19 : UnaryOp[VA19,O,RV19])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16), op17(v._17), op18(v._18), op19(v._19));\n  }\n\n  implicit def OpTuple20[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16], op17 : UnaryOp[VA17,O,RV17], op18 : UnaryOp[VA18,O,RV18], op19 : UnaryOp[VA19,O,RV19], op20 : UnaryOp[VA20,O,RV20])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16), op17(v._17), op18(v._18), op19(v._19), op20(v._20));\n  }\n\n  implicit def OpTuple21[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16], op17 : UnaryOp[VA17,O,RV17], op18 : UnaryOp[VA18,O,RV18], op19 : UnaryOp[VA19,O,RV19], op20 : UnaryOp[VA20,O,RV20], op21 : UnaryOp[VA21,O,RV21])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16), op17(v._17), op18(v._18), op19(v._19), op20(v._20), op21(v._21));\n  }\n\n  implicit def OpTuple22[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22,O<:OpType]\n  (implicit op1 : UnaryOp[VA1,O,RV1], op2 : UnaryOp[VA2,O,RV2], op3 : UnaryOp[VA3,O,RV3], op4 : UnaryOp[VA4,O,RV4], op5 : UnaryOp[VA5,O,RV5], op6 : UnaryOp[VA6,O,RV6], op7 : UnaryOp[VA7,O,RV7], op8 : UnaryOp[VA8,O,RV8], op9 : UnaryOp[VA9,O,RV9], op10 : UnaryOp[VA10,O,RV10], op11 : UnaryOp[VA11,O,RV11], op12 : UnaryOp[VA12,O,RV12], op13 : UnaryOp[VA13,O,RV13], op14 : UnaryOp[VA14,O,RV14], op15 : UnaryOp[VA15,O,RV15], op16 : UnaryOp[VA16,O,RV16], op17 : UnaryOp[VA17,O,RV17], op18 : UnaryOp[VA18,O,RV18], op19 : UnaryOp[VA19,O,RV19], op20 : UnaryOp[VA20,O,RV20], op21 : UnaryOp[VA21,O,RV21], op22 : UnaryOp[VA22,O,RV22])\n  : UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)]\n  = new UnaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)] {\n    def opType = op1.opType;\n    def apply(v : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22)) = (op1(v._1), op2(v._2), op3(v._3), op4(v._4), op5(v._5), op6(v._6), op7(v._7), op8(v._8), op9(v._9), op10(v._10), op11(v._11), op12(v._12), op13(v._13), op14(v._14), op15(v._15), op16(v._16), op17(v._17), op18(v._18), op19(v._19), op20(v._20), op21(v._21), op22(v._22));\n  }\n}\n\n/**\n * Binary operator support for tuples of aritys 2 to 22.\n *\n * @author dramage\n */\ntrait BinaryTupleOps {\n  implicit def OpTuple2Tuple2[VA1,VA2,VB1,VB2,RV1,RV2,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2])\n  : BinaryOp[(VA1,VA2),(VB1,VB2),O,(RV1,RV2)]\n  = new BinaryOp[(VA1,VA2),(VB1,VB2),O,(RV1,RV2)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2), b : (VB1,VB2)) = (op1(a._1,b._1), op2(a._2,b._2));\n  }\n\n\n  implicit def OpTuple2Scalar[VA1,VA2,VS,RV1,RV2,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2),VS,O,(RV1,RV2)]\n  = new BinaryOp[(VA1,VA2),VS,O,(RV1,RV2)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2), s : VS) = (op1(a._1,s), op2(a._2,s));\n  }\n\n\n  implicit def OpScalarTuple2[VS,VB1,VB2,RV1,RV2,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2),O,(RV1,RV2)]\n  = new BinaryOp[VS,(VB1,VB2),O,(RV1,RV2)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2)) = (op1(s,b._1), op2(s,b._2));\n  }\n\n\n  implicit def OpTuple3Tuple3[VA1,VA2,VA3,VB1,VB2,VB3,RV1,RV2,RV3,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3])\n  : BinaryOp[(VA1,VA2,VA3),(VB1,VB2,VB3),O,(RV1,RV2,RV3)]\n  = new BinaryOp[(VA1,VA2,VA3),(VB1,VB2,VB3),O,(RV1,RV2,RV3)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3), b : (VB1,VB2,VB3)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3));\n  }\n\n\n  implicit def OpTuple3Scalar[VA1,VA2,VA3,VS,RV1,RV2,RV3,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3),VS,O,(RV1,RV2,RV3)]\n  = new BinaryOp[(VA1,VA2,VA3),VS,O,(RV1,RV2,RV3)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s));\n  }\n\n\n  implicit def OpScalarTuple3[VS,VB1,VB2,VB3,RV1,RV2,RV3,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3),O,(RV1,RV2,RV3)]\n  = new BinaryOp[VS,(VB1,VB2,VB3),O,(RV1,RV2,RV3)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3));\n  }\n\n\n  implicit def OpTuple4Tuple4[VA1,VA2,VA3,VA4,VB1,VB2,VB3,VB4,RV1,RV2,RV3,RV4,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4])\n  : BinaryOp[(VA1,VA2,VA3,VA4),(VB1,VB2,VB3,VB4),O,(RV1,RV2,RV3,RV4)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4),(VB1,VB2,VB3,VB4),O,(RV1,RV2,RV3,RV4)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4), b : (VB1,VB2,VB3,VB4)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4));\n  }\n\n\n  implicit def OpTuple4Scalar[VA1,VA2,VA3,VA4,VS,RV1,RV2,RV3,RV4,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4),VS,O,(RV1,RV2,RV3,RV4)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4),VS,O,(RV1,RV2,RV3,RV4)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s));\n  }\n\n\n  implicit def OpScalarTuple4[VS,VB1,VB2,VB3,VB4,RV1,RV2,RV3,RV4,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4),O,(RV1,RV2,RV3,RV4)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4),O,(RV1,RV2,RV3,RV4)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4));\n  }\n\n\n  implicit def OpTuple5Tuple5[VA1,VA2,VA3,VA4,VA5,VB1,VB2,VB3,VB4,VB5,RV1,RV2,RV3,RV4,RV5,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5),(VB1,VB2,VB3,VB4,VB5),O,(RV1,RV2,RV3,RV4,RV5)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5),(VB1,VB2,VB3,VB4,VB5),O,(RV1,RV2,RV3,RV4,RV5)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5), b : (VB1,VB2,VB3,VB4,VB5)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5));\n  }\n\n\n  implicit def OpTuple5Scalar[VA1,VA2,VA3,VA4,VA5,VS,RV1,RV2,RV3,RV4,RV5,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5),VS,O,(RV1,RV2,RV3,RV4,RV5)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5),VS,O,(RV1,RV2,RV3,RV4,RV5)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s));\n  }\n\n\n  implicit def OpScalarTuple5[VS,VB1,VB2,VB3,VB4,VB5,RV1,RV2,RV3,RV4,RV5,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5),O,(RV1,RV2,RV3,RV4,RV5)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5),O,(RV1,RV2,RV3,RV4,RV5)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5));\n  }\n\n\n  implicit def OpTuple6Tuple6[VA1,VA2,VA3,VA4,VA5,VA6,VB1,VB2,VB3,VB4,VB5,VB6,RV1,RV2,RV3,RV4,RV5,RV6,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6),(VB1,VB2,VB3,VB4,VB5,VB6),O,(RV1,RV2,RV3,RV4,RV5,RV6)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6),(VB1,VB2,VB3,VB4,VB5,VB6),O,(RV1,RV2,RV3,RV4,RV5,RV6)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6), b : (VB1,VB2,VB3,VB4,VB5,VB6)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6));\n  }\n\n\n  implicit def OpTuple6Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VS,RV1,RV2,RV3,RV4,RV5,RV6,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s));\n  }\n\n\n  implicit def OpScalarTuple6[VS,VB1,VB2,VB3,VB4,VB5,VB6,RV1,RV2,RV3,RV4,RV5,RV6,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6),O,(RV1,RV2,RV3,RV4,RV5,RV6)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6),O,(RV1,RV2,RV3,RV4,RV5,RV6)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6));\n  }\n\n\n  implicit def OpTuple7Tuple7[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VB1,VB2,VB3,VB4,VB5,VB6,VB7,RV1,RV2,RV3,RV4,RV5,RV6,RV7,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7),(VB1,VB2,VB3,VB4,VB5,VB6,VB7),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7),(VB1,VB2,VB3,VB4,VB5,VB6,VB7),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7));\n  }\n\n\n  implicit def OpTuple7Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s));\n  }\n\n\n  implicit def OpScalarTuple7[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,RV1,RV2,RV3,RV4,RV5,RV6,RV7,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7));\n  }\n\n\n  implicit def OpTuple8Tuple8[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8));\n  }\n\n\n  implicit def OpTuple8Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s));\n  }\n\n\n  implicit def OpScalarTuple8[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8));\n  }\n\n\n  implicit def OpTuple9Tuple9[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9));\n  }\n\n\n  implicit def OpTuple9Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s));\n  }\n\n\n  implicit def OpScalarTuple9[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9));\n  }\n\n\n  implicit def OpTuple10Tuple10[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10));\n  }\n\n\n  implicit def OpTuple10Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s));\n  }\n\n\n  implicit def OpScalarTuple10[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10));\n  }\n\n\n  implicit def OpTuple11Tuple11[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11));\n  }\n\n\n  implicit def OpTuple11Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s));\n  }\n\n\n  implicit def OpScalarTuple11[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11));\n  }\n\n\n  implicit def OpTuple12Tuple12[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12));\n  }\n\n\n  implicit def OpTuple12Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s));\n  }\n\n\n  implicit def OpScalarTuple12[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12));\n  }\n\n\n  implicit def OpTuple13Tuple13[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13));\n  }\n\n\n  implicit def OpTuple13Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s));\n  }\n\n\n  implicit def OpScalarTuple13[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13));\n  }\n\n\n  implicit def OpTuple14Tuple14[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14));\n  }\n\n\n  implicit def OpTuple14Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s));\n  }\n\n\n  implicit def OpScalarTuple14[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14));\n  }\n\n\n  implicit def OpTuple15Tuple15[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15));\n  }\n\n\n  implicit def OpTuple15Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s));\n  }\n\n\n  implicit def OpScalarTuple15[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15));\n  }\n\n\n  implicit def OpTuple16Tuple16[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16));\n  }\n\n\n  implicit def OpTuple16Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s));\n  }\n\n\n  implicit def OpScalarTuple16[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16));\n  }\n\n\n  implicit def OpTuple17Tuple17[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], op17 : BinaryOp[VA17,VB17,O,RV17], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16], c17 : CompatibleShape[VA17,VB17])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16), op17(a._17,b._17));\n  }\n\n\n  implicit def OpTuple17Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], op17 : BinaryOp[VA17,VS,O,RV17], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s), op17(a._17,s));\n  }\n\n\n  implicit def OpScalarTuple17[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], op17 : BinaryOp[VS,VB17,O,RV17], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16), op17(s,b._17));\n  }\n\n\n  implicit def OpTuple18Tuple18[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], op17 : BinaryOp[VA17,VB17,O,RV17], op18 : BinaryOp[VA18,VB18,O,RV18], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16], c17 : CompatibleShape[VA17,VB17], c18 : CompatibleShape[VA18,VB18])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16), op17(a._17,b._17), op18(a._18,b._18));\n  }\n\n\n  implicit def OpTuple18Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], op17 : BinaryOp[VA17,VS,O,RV17], op18 : BinaryOp[VA18,VS,O,RV18], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s), op17(a._17,s), op18(a._18,s));\n  }\n\n\n  implicit def OpScalarTuple18[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], op17 : BinaryOp[VS,VB17,O,RV17], op18 : BinaryOp[VS,VB18,O,RV18], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16), op17(s,b._17), op18(s,b._18));\n  }\n\n\n  implicit def OpTuple19Tuple19[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], op17 : BinaryOp[VA17,VB17,O,RV17], op18 : BinaryOp[VA18,VB18,O,RV18], op19 : BinaryOp[VA19,VB19,O,RV19], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16], c17 : CompatibleShape[VA17,VB17], c18 : CompatibleShape[VA18,VB18], c19 : CompatibleShape[VA19,VB19])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16), op17(a._17,b._17), op18(a._18,b._18), op19(a._19,b._19));\n  }\n\n\n  implicit def OpTuple19Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], op17 : BinaryOp[VA17,VS,O,RV17], op18 : BinaryOp[VA18,VS,O,RV18], op19 : BinaryOp[VA19,VS,O,RV19], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s), op17(a._17,s), op18(a._18,s), op19(a._19,s));\n  }\n\n\n  implicit def OpScalarTuple19[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], op17 : BinaryOp[VS,VB17,O,RV17], op18 : BinaryOp[VS,VB18,O,RV18], op19 : BinaryOp[VS,VB19,O,RV19], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16), op17(s,b._17), op18(s,b._18), op19(s,b._19));\n  }\n\n\n  implicit def OpTuple20Tuple20[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], op17 : BinaryOp[VA17,VB17,O,RV17], op18 : BinaryOp[VA18,VB18,O,RV18], op19 : BinaryOp[VA19,VB19,O,RV19], op20 : BinaryOp[VA20,VB20,O,RV20], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16], c17 : CompatibleShape[VA17,VB17], c18 : CompatibleShape[VA18,VB18], c19 : CompatibleShape[VA19,VB19], c20 : CompatibleShape[VA20,VB20])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16), op17(a._17,b._17), op18(a._18,b._18), op19(a._19,b._19), op20(a._20,b._20));\n  }\n\n\n  implicit def OpTuple20Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], op17 : BinaryOp[VA17,VS,O,RV17], op18 : BinaryOp[VA18,VS,O,RV18], op19 : BinaryOp[VA19,VS,O,RV19], op20 : BinaryOp[VA20,VS,O,RV20], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s), op17(a._17,s), op18(a._18,s), op19(a._19,s), op20(a._20,s));\n  }\n\n\n  implicit def OpScalarTuple20[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], op17 : BinaryOp[VS,VB17,O,RV17], op18 : BinaryOp[VS,VB18,O,RV18], op19 : BinaryOp[VS,VB19,O,RV19], op20 : BinaryOp[VS,VB20,O,RV20], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16), op17(s,b._17), op18(s,b._18), op19(s,b._19), op20(s,b._20));\n  }\n\n\n  implicit def OpTuple21Tuple21[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], op17 : BinaryOp[VA17,VB17,O,RV17], op18 : BinaryOp[VA18,VB18,O,RV18], op19 : BinaryOp[VA19,VB19,O,RV19], op20 : BinaryOp[VA20,VB20,O,RV20], op21 : BinaryOp[VA21,VB21,O,RV21], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16], c17 : CompatibleShape[VA17,VB17], c18 : CompatibleShape[VA18,VB18], c19 : CompatibleShape[VA19,VB19], c20 : CompatibleShape[VA20,VB20], c21 : CompatibleShape[VA21,VB21])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16), op17(a._17,b._17), op18(a._18,b._18), op19(a._19,b._19), op20(a._20,b._20), op21(a._21,b._21));\n  }\n\n\n  implicit def OpTuple21Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], op17 : BinaryOp[VA17,VS,O,RV17], op18 : BinaryOp[VA18,VS,O,RV18], op19 : BinaryOp[VA19,VS,O,RV19], op20 : BinaryOp[VA20,VS,O,RV20], op21 : BinaryOp[VA21,VS,O,RV21], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s), op17(a._17,s), op18(a._18,s), op19(a._19,s), op20(a._20,s), op21(a._21,s));\n  }\n\n\n  implicit def OpScalarTuple21[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], op17 : BinaryOp[VS,VB17,O,RV17], op18 : BinaryOp[VS,VB18,O,RV18], op19 : BinaryOp[VS,VB19,O,RV19], op20 : BinaryOp[VS,VB20,O,RV20], op21 : BinaryOp[VS,VB21,O,RV21], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16), op17(s,b._17), op18(s,b._18), op19(s,b._19), op20(s,b._20), op21(s,b._21));\n  }\n\n\n  implicit def OpTuple22Tuple22[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VB1,O,RV1], op2 : BinaryOp[VA2,VB2,O,RV2], op3 : BinaryOp[VA3,VB3,O,RV3], op4 : BinaryOp[VA4,VB4,O,RV4], op5 : BinaryOp[VA5,VB5,O,RV5], op6 : BinaryOp[VA6,VB6,O,RV6], op7 : BinaryOp[VA7,VB7,O,RV7], op8 : BinaryOp[VA8,VB8,O,RV8], op9 : BinaryOp[VA9,VB9,O,RV9], op10 : BinaryOp[VA10,VB10,O,RV10], op11 : BinaryOp[VA11,VB11,O,RV11], op12 : BinaryOp[VA12,VB12,O,RV12], op13 : BinaryOp[VA13,VB13,O,RV13], op14 : BinaryOp[VA14,VB14,O,RV14], op15 : BinaryOp[VA15,VB15,O,RV15], op16 : BinaryOp[VA16,VB16,O,RV16], op17 : BinaryOp[VA17,VB17,O,RV17], op18 : BinaryOp[VA18,VB18,O,RV18], op19 : BinaryOp[VA19,VB19,O,RV19], op20 : BinaryOp[VA20,VB20,O,RV20], op21 : BinaryOp[VA21,VB21,O,RV21], op22 : BinaryOp[VA22,VB22,O,RV22], c1 : CompatibleShape[VA1,VB1], c2 : CompatibleShape[VA2,VB2], c3 : CompatibleShape[VA3,VB3], c4 : CompatibleShape[VA4,VB4], c5 : CompatibleShape[VA5,VB5], c6 : CompatibleShape[VA6,VB6], c7 : CompatibleShape[VA7,VB7], c8 : CompatibleShape[VA8,VB8], c9 : CompatibleShape[VA9,VB9], c10 : CompatibleShape[VA10,VB10], c11 : CompatibleShape[VA11,VB11], c12 : CompatibleShape[VA12,VB12], c13 : CompatibleShape[VA13,VB13], c14 : CompatibleShape[VA14,VB14], c15 : CompatibleShape[VA15,VB15], c16 : CompatibleShape[VA16,VB16], c17 : CompatibleShape[VA17,VB17], c18 : CompatibleShape[VA18,VB18], c19 : CompatibleShape[VA19,VB19], c20 : CompatibleShape[VA20,VB20], c21 : CompatibleShape[VA21,VB21], c22 : CompatibleShape[VA22,VB22])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22),(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22), b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22)) = (op1(a._1,b._1), op2(a._2,b._2), op3(a._3,b._3), op4(a._4,b._4), op5(a._5,b._5), op6(a._6,b._6), op7(a._7,b._7), op8(a._8,b._8), op9(a._9,b._9), op10(a._10,b._10), op11(a._11,b._11), op12(a._12,b._12), op13(a._13,b._13), op14(a._14,b._14), op15(a._15,b._15), op16(a._16,b._16), op17(a._17,b._17), op18(a._18,b._18), op19(a._19,b._19), op20(a._20,b._20), op21(a._21,b._21), op22(a._22,b._22));\n  }\n\n\n  implicit def OpTuple22Scalar[VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22,VS,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22,O<:OpType]\n  (implicit op1 : BinaryOp[VA1,VS,O,RV1], op2 : BinaryOp[VA2,VS,O,RV2], op3 : BinaryOp[VA3,VS,O,RV3], op4 : BinaryOp[VA4,VS,O,RV4], op5 : BinaryOp[VA5,VS,O,RV5], op6 : BinaryOp[VA6,VS,O,RV6], op7 : BinaryOp[VA7,VS,O,RV7], op8 : BinaryOp[VA8,VS,O,RV8], op9 : BinaryOp[VA9,VS,O,RV9], op10 : BinaryOp[VA10,VS,O,RV10], op11 : BinaryOp[VA11,VS,O,RV11], op12 : BinaryOp[VA12,VS,O,RV12], op13 : BinaryOp[VA13,VS,O,RV13], op14 : BinaryOp[VA14,VS,O,RV14], op15 : BinaryOp[VA15,VS,O,RV15], op16 : BinaryOp[VA16,VS,O,RV16], op17 : BinaryOp[VA17,VS,O,RV17], op18 : BinaryOp[VA18,VS,O,RV18], op19 : BinaryOp[VA19,VS,O,RV19], op20 : BinaryOp[VA20,VS,O,RV20], op21 : BinaryOp[VA21,VS,O,RV21], op22 : BinaryOp[VA22,VS,O,RV22], s : Scalar[VS])\n  : BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)]\n  = new BinaryOp[(VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22),VS,O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)] {\n    def opType = op1.opType;\n    def apply(a : (VA1,VA2,VA3,VA4,VA5,VA6,VA7,VA8,VA9,VA10,VA11,VA12,VA13,VA14,VA15,VA16,VA17,VA18,VA19,VA20,VA21,VA22), s : VS) = (op1(a._1,s), op2(a._2,s), op3(a._3,s), op4(a._4,s), op5(a._5,s), op6(a._6,s), op7(a._7,s), op8(a._8,s), op9(a._9,s), op10(a._10,s), op11(a._11,s), op12(a._12,s), op13(a._13,s), op14(a._14,s), op15(a._15,s), op16(a._16,s), op17(a._17,s), op18(a._18,s), op19(a._19,s), op20(a._20,s), op21(a._21,s), op22(a._22,s));\n  }\n\n\n  implicit def OpScalarTuple22[VS,VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22,RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22,O<:OpType]\n  (implicit op1 : BinaryOp[VS,VB1,O,RV1], op2 : BinaryOp[VS,VB2,O,RV2], op3 : BinaryOp[VS,VB3,O,RV3], op4 : BinaryOp[VS,VB4,O,RV4], op5 : BinaryOp[VS,VB5,O,RV5], op6 : BinaryOp[VS,VB6,O,RV6], op7 : BinaryOp[VS,VB7,O,RV7], op8 : BinaryOp[VS,VB8,O,RV8], op9 : BinaryOp[VS,VB9,O,RV9], op10 : BinaryOp[VS,VB10,O,RV10], op11 : BinaryOp[VS,VB11,O,RV11], op12 : BinaryOp[VS,VB12,O,RV12], op13 : BinaryOp[VS,VB13,O,RV13], op14 : BinaryOp[VS,VB14,O,RV14], op15 : BinaryOp[VS,VB15,O,RV15], op16 : BinaryOp[VS,VB16,O,RV16], op17 : BinaryOp[VS,VB17,O,RV17], op18 : BinaryOp[VS,VB18,O,RV18], op19 : BinaryOp[VS,VB19,O,RV19], op20 : BinaryOp[VS,VB20,O,RV20], op21 : BinaryOp[VS,VB21,O,RV21], op22 : BinaryOp[VS,VB22,O,RV22], s : Scalar[VS])\n  : BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)]\n  = new BinaryOp[VS,(VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22),O,(RV1,RV2,RV3,RV4,RV5,RV6,RV7,RV8,RV9,RV10,RV11,RV12,RV13,RV14,RV15,RV16,RV17,RV18,RV19,RV20,RV21,RV22)] {\n    def opType = op1.opType;\n    def apply(s : VS, b : (VB1,VB2,VB3,VB4,VB5,VB6,VB7,VB8,VB9,VB10,VB11,VB12,VB13,VB14,VB15,VB16,VB17,VB18,VB19,VB20,VB21,VB22)) = (op1(s,b._1), op2(s,b._2), op3(s,b._3), op4(s,b._4), op5(s,b._5), op6(s,b._6), op7(s,b._7), op8(s,b._8), op9(s,b._9), op10(s,b._10), op11(s,b._11), op12(s,b._12), op13(s,b._13), op14(s,b._14), op15(s,b._15), op16(s,b._16), op17(s,b._17), op18(s,b._18), op19(s,b._19), op20(s,b._20), op21(s,b._21), op22(s,b._22));\n  }\n}\n\nobject RichTuples {\n  class RichTuple2[@specialized V1, @specialized V2](override val repr : (V1,V2)) extends MutableNumericOps[(V1,V2)];\n\n  class RichTuple3[@specialized V1, @specialized V2, @specialized V3](override val repr : (V1,V2,V3)) extends MutableNumericOps[(V1,V2,V3)];\n\n  class RichTuple4[V1, V2, V3, V4](override val repr : (V1,V2,V3,V4)) extends MutableNumericOps[(V1,V2,V3,V4)];\n\n  class RichTuple5[V1, V2, V3, V4, V5](override val repr : (V1,V2,V3,V4,V5)) extends MutableNumericOps[(V1,V2,V3,V4,V5)];\n\n  class RichTuple6[V1, V2, V3, V4, V5, V6](override val repr : (V1,V2,V3,V4,V5,V6)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6)];\n\n  class RichTuple7[V1, V2, V3, V4, V5, V6, V7](override val repr : (V1,V2,V3,V4,V5,V6,V7)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7)];\n\n  class RichTuple8[V1, V2, V3, V4, V5, V6, V7, V8](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8)];\n\n  class RichTuple9[V1, V2, V3, V4, V5, V6, V7, V8, V9](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9)];\n\n  class RichTuple10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10)];\n\n  class RichTuple11[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11)];\n\n  class RichTuple12[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12)];\n\n  class RichTuple13[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13)];\n\n  class RichTuple14[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14)];\n\n  class RichTuple15[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15)];\n\n  class RichTuple16[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16)];\n\n  class RichTuple17[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17)];\n\n  class RichTuple18[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18)];\n\n  class RichTuple19[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19)];\n\n  class RichTuple20[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20)];\n\n  class RichTuple21[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21)];\n\n  class RichTuple22[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22](override val repr : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21,V22)) extends MutableNumericOps[(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21,V22)];\n\n}\n\n\ntrait RichTupleImplicits {\n  import RichTuples._;\n  \n  implicit def richTuple2[@specialized V1, @specialized V2](value : (V1,V2)) = new RichTuple2(value);\n\n  implicit def richTuple3[@specialized V1, @specialized V2, @specialized V3](value : (V1,V2,V3)) = new RichTuple3(value);\n\n  implicit def richTuple4[V1, V2, V3, V4](value : (V1,V2,V3,V4)) = new RichTuple4(value);\n\n  implicit def richTuple5[V1, V2, V3, V4, V5](value : (V1,V2,V3,V4,V5)) = new RichTuple5(value);\n\n  implicit def richTuple6[V1, V2, V3, V4, V5, V6](value : (V1,V2,V3,V4,V5,V6)) = new RichTuple6(value);\n\n  implicit def richTuple7[V1, V2, V3, V4, V5, V6, V7](value : (V1,V2,V3,V4,V5,V6,V7)) = new RichTuple7(value);\n\n  implicit def richTuple8[V1, V2, V3, V4, V5, V6, V7, V8](value : (V1,V2,V3,V4,V5,V6,V7,V8)) = new RichTuple8(value);\n\n  implicit def richTuple9[V1, V2, V3, V4, V5, V6, V7, V8, V9](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9)) = new RichTuple9(value);\n\n  implicit def richTuple10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10)) = new RichTuple10(value);\n\n  implicit def richTuple11[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11)) = new RichTuple11(value);\n\n  implicit def richTuple12[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12)) = new RichTuple12(value);\n\n  implicit def richTuple13[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13)) = new RichTuple13(value);\n\n  implicit def richTuple14[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14)) = new RichTuple14(value);\n\n  implicit def richTuple15[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15)) = new RichTuple15(value);\n\n  implicit def richTuple16[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16)) = new RichTuple16(value);\n\n  implicit def richTuple17[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17)) = new RichTuple17(value);\n\n  implicit def richTuple18[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18)) = new RichTuple18(value);\n\n  implicit def richTuple19[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19)) = new RichTuple19(value);\n\n  implicit def richTuple20[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20)) = new RichTuple20(value);\n\n  implicit def richTuple21[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21)) = new RichTuple21(value);\n\n  implicit def richTuple22[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22](value : (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,V20,V21,V22)) = new RichTuple22(value);\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/UnaryOp.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala;\npackage operators;\n\nimport scala.annotation.implicitNotFound;\nimport scala.collection.generic.CanBuildFrom;\n\n/**\n * Operation of type O that returns That from arguments A and B.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"Could not find a way to ${O} value of type ${This}\")\ntrait UnaryOp[@specialized -This, O<:OpType, +That] {\n  // should not inherit from This=>That because the compiler will try to use it as a conversion.\n  def opType : O;\n  def apply(t: This):That\n}\n\nobject UnaryOp extends UnaryTupleOps {\n  \n  //\n  // Negation\n  //\n  \n  implicit object OpNegI extends UnaryOp[Int,OpNeg,Int]\n    { def opType = OpNeg; def apply(v : Int) = -v; }\n\n  implicit object OpNegS extends UnaryOp[Short,OpNeg,Short]\n    { def opType = OpNeg; def apply(v : Short) = (-v).asInstanceOf[Short]; }\n\n  implicit object OpNegL extends UnaryOp[Long,OpNeg,Long]\n    { def opType = OpNeg; def apply(v : Long) = -v; }\n\n  implicit object OpNegF extends UnaryOp[Float,OpNeg,Float]\n    { def opType = OpNeg; def apply(v : Float) = -v; }\n\n  implicit object OpNegD extends UnaryOp[Double,OpNeg,Double]\n    { def opType = OpNeg; def apply(v : Double) = -v; }\n  \n  //\n  // Not\n  //\n  \n  implicit object OpNotB extends UnaryOp[Boolean,OpNot,Boolean]\n    { def opType = OpNot; def apply(v : Boolean) = !v; }\n  \n  //\n  // Maps\n  //\n  \n  implicit def OpMap[K,V,RV,O<:OpType,M,That]\n  (implicit view : M=>scala.collection.Map[K,V],\n    op : UnaryOp[V,O,RV], bf : CanBuildFrom[M,(K,RV),That])\n  : UnaryOp[M, O, That]\n  = new UnaryOp[M, O, That] {\n    def opType = op.opType;\n    def apply(m : M) = {\n      val builder = bf(m);\n      for ((k,v) <- m) {\n        builder += k -> op(v);\n      }\n      builder.result;\n    }\n  }\n  \n  //\n  // Seqs\n  //\n\n  implicit def OpSeq[V,RV,O<:OpType,S,That]\n  (implicit view : S=>scala.collection.Seq[V], op : UnaryOp[V,O,RV],\n   bf : CanBuildFrom[S,RV,That])\n  : UnaryOp[S,O,That]\n  = new UnaryOp[S,O,That] {\n    def opType = op.opType;\n    def apply(s : S) = {\n      val builder = bf(s);\n      for (v <- s) {\n        builder += op(v);\n      }\n      builder.result;\n    }\n  }\n  \n  //\n  // Arrays\n  //\n\n  implicit def OpArray[V,RV,O<:OpType]\n  (implicit op : UnaryOp[V,O,RV], mf : Manifest[RV])\n  : UnaryOp[Array[V],O,Array[RV]]\n  = new UnaryOp[Array[V],O,Array[RV]] {\n    def opType = op.opType;\n    def apply(a : Array[V]) = {\n      var rv = new Array[RV](a.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = op(a(i));\n        i += 1;\n      }\n      rv;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/ValuesMonadic.scala",
    "content": "package scalala.operators\n\nimport scalala.generic.collection.CanMapValues\n\n/**\n *\n * Represents objects that can have their values mapped.\n * @author dlwh\n */\ntrait ValuesMonadic[+This,V] {\n  def repr: This;\n  def map[TT>:This,O,That](fn : V => O)\n  (implicit bf : CanMapValues[TT, V, O, That]) : That =\n    bf.map(repr,fn);\n\n}\n\ntrait HasValuesMonadic[+This,V] {\n  def values: ValuesMonadic[This,V];\n}\n\nobject HasValuesMonadic {\n  implicit def arrayHasValues[V](arr: Array[V]): HasValuesMonadic[Array[V], V]  = new HasValuesMonadic[Array[V],V] {\n    def values = new ValuesMonadic[Array[V],V] {\n      def repr = arr;\n    }\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/operators/bundles/VectorSpace.scala",
    "content": "package scalala\npackage operators\npackage bundles\n\nimport scalar.Scalar\nimport generic.math.CanNorm\nimport generic.collection.{CanZipMapValues, CanCopy, CanMapValues, CanCreateZerosLike}\n\n/**\n * A VectorSpace has vectors S with vector addition and multiplication\n * by scalars, along with a privileged zero vector.\n * We add in implicits for operations that fall out of them.\n * @author dlwh\n */\ntrait VectorSpace[S,V] {\n  implicit def field : Scalar[S]\n  implicit def numericOps(t: V):NumericOps[V];\n  implicit def hasValuesMonadic(t: V):HasValuesMonadic[V,S]\n  implicit def mapValues: CanMapValues[V,S,S,V]\n  implicit def zipMapValues: CanZipMapValues[V,S,S,V]\n\n  implicit val zeros: CanCreateZerosLike[V, V];\n  def ones(v: V) = zeros(v) + field.one;\n\n//  implicit def negV : UnaryOp[V,OpNeg,V];\n\n  implicit def addSV : BinaryOp[S,V,OpAdd,V];\n  implicit def addVS : BinaryOp[V,S,OpAdd,V];\n  implicit def addVV : BinaryOp[V,V,OpAdd,V];\n\n  implicit def subSV : BinaryOp[S,V,OpSub,V];\n  implicit def subVS : BinaryOp[V,S,OpSub,V];\n  implicit def subVV : BinaryOp[V,V,OpSub,V];\n\n  implicit def mulSV : BinaryOp[S,V,OpMul,V];\n  implicit def mulVS : BinaryOp[V,S,OpMul,V];\n  implicit def mulVV : BinaryOp[V,V,OpMul,V];\n\n  implicit def divSV : BinaryOp[S,V,OpDiv,V];\n  implicit def divVS : BinaryOp[V,S,OpDiv,V];\n  implicit def divVV : BinaryOp[V,V,OpDiv,V];\n}\n\n/**\n * Adds in mutating operations\n * @author dlwh\n */\ntrait MutableVectorSpace[S,V] extends VectorSpace[S,V] {\n\n  override implicit def numericOps(t: V):MutableNumericOps[V]\n  implicit val copy: CanCopy[V];\n\n  implicit def addIntoVS : BinaryUpdateOp[V,S,OpAdd];\n  implicit def addIntoVV : BinaryUpdateOp[V,V,OpAdd];\n\n  implicit def subIntoVS : BinaryUpdateOp[V,S,OpSub];\n  implicit def subIntoVV : BinaryUpdateOp[V,V,OpSub];\n\n  implicit def divIntoVS : BinaryUpdateOp[V,S,OpDiv];\n  implicit def divIntoVV : BinaryUpdateOp[V,V,OpDiv];\n\n  implicit def mulIntoVS : BinaryUpdateOp[V,S,OpMul];\n  implicit def mulIntoVV : BinaryUpdateOp[V,V,OpMul];\n}\n\n\n\nobject VectorSpace {\n  implicit def make[V,S](implicit _field : Scalar[S],\n                         _numericOps: V=>NumericOps[V],\n                         _hasValuesMonadic: V=>HasValuesMonadic[V,S],\n                         _mapValues: CanMapValues[V,S,S,V],\n                         _zipMapValues: CanZipMapValues[V,S,S,V],\n                         _zeros: CanCreateZerosLike[V, V],\n//                         _negV : UnaryOp[V,OpNeg,V],\n                         _addSV : BinaryOp[S,V,OpAdd,V],\n                         _addVS : BinaryOp[V,S,OpAdd,V],\n                         _addVV : BinaryOp[V,V,OpAdd,V],\n\n                         _subSV : BinaryOp[S,V,OpSub,V],\n                         _subVS : BinaryOp[V,S,OpSub,V],\n                         _subVV : BinaryOp[V,V,OpSub,V],\n\n                         _mulSV : BinaryOp[S,V,OpMul,V],\n                         _mulVS : BinaryOp[V,S,OpMul,V],\n                         _mulVV : BinaryOp[V,V,OpMul,V],\n\n                         _divSV : BinaryOp[S,V,OpDiv,V],\n                         _divVS : BinaryOp[V,S,OpDiv,V],\n                         _divVV : BinaryOp[V,V,OpDiv,V]):VectorSpace[S,V] = {\n    new VectorSpace[S,V] {\n      def field : Scalar[S] = _field;\n      def numericOps(t: V):NumericOps[V] = _numericOps(t)\n      def hasValuesMonadic(t: V):HasValuesMonadic[V,S] = _hasValuesMonadic(t)\n      def mapValues: CanMapValues[V,S,S,V] = _mapValues;\n      def zipMapValues: CanZipMapValues[V,S,S,V] = _zipMapValues;\n\n      implicit val zeros: CanCreateZerosLike[V, V] = _zeros\n\n//      implicit def negV : UnaryOp[V,OpNeg,V] = _negV;\n\n      implicit def addSV : BinaryOp[S,V,OpAdd,V] = _addSV;\n      implicit def addVS : BinaryOp[V,S,OpAdd,V] = _addVS;\n      implicit def addVV : BinaryOp[V,V,OpAdd,V] = _addVV;\n\n      implicit def subSV : BinaryOp[S,V,OpSub,V] = _subSV;\n      implicit def subVS : BinaryOp[V,S,OpSub,V] = _subVS;\n      implicit def subVV : BinaryOp[V,V,OpSub,V] = _subVV;\n\n      implicit def mulSV : BinaryOp[S,V,OpMul,V] = _mulSV;\n      implicit def mulVS : BinaryOp[V,S,OpMul,V] = _mulVS;\n      implicit def mulVV : BinaryOp[V,V,OpMul,V] = _mulVV;\n\n      implicit def divSV : BinaryOp[S,V,OpDiv,V] = _divSV;\n      implicit def divVS : BinaryOp[V,S,OpDiv,V] = _divVS;\n      implicit def divVV : BinaryOp[V,V,OpDiv,V] = _divVV;\n    }\n  }\n\n}\n\nobject MutableVectorSpace {\n  implicit def make[V,S](implicit _field : Scalar[S],\n                         _numericOps: V=>MutableNumericOps[V],\n\n                         _hasValuesMonadic: V=>HasValuesMonadic[V,S],\n                         _mapValues: CanMapValues[V,S,S,V],\n                         _zipMapValues: CanZipMapValues[V,S,S,V],\n                         _zeros: CanCreateZerosLike[V, V],\n                         _copy: CanCopy[V],\n//                         _negV : UnaryOp[V,OpNeg,V],\n                         _addSV : BinaryOp[S,V,OpAdd,V],\n                         _addVS : BinaryOp[V,S,OpAdd,V],\n                         _addVV : BinaryOp[V,V,OpAdd,V],\n\n                         _subSV : BinaryOp[S,V,OpSub,V],\n                         _subVS : BinaryOp[V,S,OpSub,V],\n                         _subVV : BinaryOp[V,V,OpSub,V],\n\n                         _mulSV : BinaryOp[S,V,OpMul,V],\n                         _mulVS : BinaryOp[V,S,OpMul,V],\n                         _mulVV : BinaryOp[V,V,OpMul,V],\n\n                         _divSV : BinaryOp[S,V,OpDiv,V],\n                         _divVS : BinaryOp[V,S,OpDiv,V],\n                         _divVV : BinaryOp[V,V,OpDiv,V],\n\n                         _addIntoVS : BinaryUpdateOp[V,S,OpAdd],\n                         _addIntoVV : BinaryUpdateOp[V,V,OpAdd],\n\n                         _mulIntoVS : BinaryUpdateOp[V,S,OpMul],\n                         _mulIntoVV : BinaryUpdateOp[V,V,OpMul],\n\n                         _subIntoVS : BinaryUpdateOp[V,S,OpSub],\n                         _subIntoVV : BinaryUpdateOp[V,V,OpSub],\n\n                         _divIntoVS : BinaryUpdateOp[V,S,OpDiv],\n                         _divIntoVV : BinaryUpdateOp[V,V,OpDiv]):MutableVectorSpace[S,V] = {\n    new MutableVectorSpace[S,V] {\n      def field : Scalar[S] = _field;\n      def numericOps(t: V) = _numericOps(t)\n      def hasValuesMonadic(t: V):HasValuesMonadic[V,S] = _hasValuesMonadic(t)\n      def mapValues: CanMapValues[V,S,S,V] = _mapValues;\n      def zipMapValues: CanZipMapValues[V,S,S,V] = _zipMapValues;\n\n      implicit val zeros: CanCreateZerosLike[V, V] = _zeros\n      implicit val copy: CanCopy[V] = _copy;\n\n//      implicit def negV : UnaryOp[V,OpNeg,V] = _negV;\n\n      implicit def addSV : BinaryOp[S,V,OpAdd,V] = _addSV;\n      implicit def addVS : BinaryOp[V,S,OpAdd,V] = _addVS;\n      implicit def addVV : BinaryOp[V,V,OpAdd,V] = _addVV;\n\n      implicit def subSV : BinaryOp[S,V,OpSub,V] = _subSV;\n      implicit def subVS : BinaryOp[V,S,OpSub,V] = _subVS;\n      implicit def subVV : BinaryOp[V,V,OpSub,V] = _subVV;\n\n      implicit def mulSV : BinaryOp[S,V,OpMul,V] = _mulSV;\n      implicit def mulVS : BinaryOp[V,S,OpMul,V] = _mulVS;\n      implicit def mulVV : BinaryOp[V,V,OpMul,V] = _mulVV;\n\n      implicit def divSV : BinaryOp[S,V,OpDiv,V] = _divSV;\n      implicit def divVS : BinaryOp[V,S,OpDiv,V] = _divVS;\n      implicit def divVV : BinaryOp[V,V,OpDiv,V] = _divVV;\n\n      implicit def divIntoVV = _divIntoVV\n      implicit def divIntoVS = _divIntoVS\n\n      implicit def subIntoVV = _subIntoVV\n      implicit def subIntoVS = _subIntoVS\n\n      implicit def addIntoVV = _addIntoVV\n      implicit def addIntoVS = _addIntoVS\n\n      implicit def mulIntoVV = _mulIntoVV\n      implicit def mulIntoVS = _mulIntoVS\n    }\n  }\n\n}\n\n/**\n * VectorSpace with an innerproduct\n * @author dlwh\n */\ntrait InnerProductSpace[S,V] extends VectorSpace[S,V] {\n  implicit def innerVV : BinaryOp[V,V,OpMulInner,S];\n}\n\nobject InnerProductSpace {\n  implicit def make[V,S](implicit _field : Scalar[S],\n                         _numericOps: V=>NumericOps[V],\n                         _hasValuesMonadic: V=>HasValuesMonadic[V,S],\n                         _mapValues: CanMapValues[V,S,S,V],\n                         _zipMapValues: CanZipMapValues[V,S,S,V],\n                         _zeros: CanCreateZerosLike[V, V],\n//                         _negV : UnaryOp[V,OpNeg,V],\n                         _addSV : BinaryOp[S,V,OpAdd,V],\n                         _addVS : BinaryOp[V,S,OpAdd,V],\n                         _addVV : BinaryOp[V,V,OpAdd,V],\n\n                         _subSV : BinaryOp[S,V,OpSub,V],\n                         _subVS : BinaryOp[V,S,OpSub,V],\n                         _subVV : BinaryOp[V,V,OpSub,V],\n\n                         _mulSV : BinaryOp[S,V,OpMul,V],\n                         _mulVS : BinaryOp[V,S,OpMul,V],\n                         _mulVV : BinaryOp[V,V,OpMul,V],\n\n                         _divSV : BinaryOp[S,V,OpDiv,V],\n                         _divVS : BinaryOp[V,S,OpDiv,V],\n                         _divVV : BinaryOp[V,V,OpDiv,V],\n                         _innerVV : BinaryOp[V,V,OpMulInner,S]):InnerProductSpace[S,V] = {\n    new InnerProductSpace[S,V] {\n      def field : Scalar[S] = _field;\n      def numericOps(t: V):NumericOps[V] = _numericOps(t)\n      def hasValuesMonadic(t: V):HasValuesMonadic[V,S] = _hasValuesMonadic(t)\n      def mapValues: CanMapValues[V,S,S,V] = _mapValues;\n      def zipMapValues: CanZipMapValues[V,S,S,V] = _zipMapValues;\n\n      implicit val zeros: CanCreateZerosLike[V, V] = _zeros\n\n//      implicit def negV : UnaryOp[V,OpNeg,V] = _negV;\n\n      implicit def addSV : BinaryOp[S,V,OpAdd,V] = _addSV;\n      implicit def addVS : BinaryOp[V,S,OpAdd,V] = _addVS;\n      implicit def addVV : BinaryOp[V,V,OpAdd,V] = _addVV;\n\n      implicit def subSV : BinaryOp[S,V,OpSub,V] = _subSV;\n      implicit def subVS : BinaryOp[V,S,OpSub,V] = _subVS;\n      implicit def subVV : BinaryOp[V,V,OpSub,V] = _subVV;\n\n      implicit def mulSV : BinaryOp[S,V,OpMul,V] = _mulSV;\n      implicit def mulVS : BinaryOp[V,S,OpMul,V] = _mulVS;\n      implicit def mulVV : BinaryOp[V,V,OpMul,V] = _mulVV;\n\n      implicit def divSV : BinaryOp[S,V,OpDiv,V] = _divSV;\n      implicit def divVS : BinaryOp[V,S,OpDiv,V] = _divVS;\n      implicit def divVV : BinaryOp[V,V,OpDiv,V] = _divVV;\n\n      implicit def innerVV : BinaryOp[V,V,OpMulInner,S] = _innerVV;\n    }\n  }\n\n}\n\n\ntrait MutableInnerProductSpace[S,V] extends InnerProductSpace[S,V] with MutableVectorSpace[S,V];\n\nobject MutableInnerProductSpace {\n  implicit def make[S,V](implicit _field : Scalar[S],\n                         _numericOps: V=>MutableNumericOps[V],\n                         _hasValuesMonadic: V=>HasValuesMonadic[V,S],\n                         _mapValues: CanMapValues[V,S,S,V],\n                         _zipMapValues: CanZipMapValues[V,S,S,V],\n                         _zeros: CanCreateZerosLike[V, V],\n                         _copy: CanCopy[V],\n//                         _negV : UnaryOp[V,OpNeg,V],\n                         _addSV : BinaryOp[S,V,OpAdd,V],\n                         _addVS : BinaryOp[V,S,OpAdd,V],\n                         _addVV : BinaryOp[V,V,OpAdd,V],\n\n                         _subSV : BinaryOp[S,V,OpSub,V],\n                         _subVS : BinaryOp[V,S,OpSub,V],\n                         _subVV : BinaryOp[V,V,OpSub,V],\n\n                         _mulSV : BinaryOp[S,V,OpMul,V],\n                         _mulVS : BinaryOp[V,S,OpMul,V],\n                         _mulVV : BinaryOp[V,V,OpMul,V],\n\n                         _divSV : BinaryOp[S,V,OpDiv,V],\n                         _divVS : BinaryOp[V,S,OpDiv,V],\n                         _divVV : BinaryOp[V,V,OpDiv,V],\n\n                         _addIntoVS : BinaryUpdateOp[V,S,OpAdd],\n                         _addIntoVV : BinaryUpdateOp[V,V,OpAdd],\n\n                         _mulIntoVS : BinaryUpdateOp[V,S,OpMul],\n                         _mulIntoVV : BinaryUpdateOp[V,V,OpMul],\n\n                         _subIntoVS : BinaryUpdateOp[V,S,OpSub],\n                         _subIntoVV : BinaryUpdateOp[V,V,OpSub],\n\n                         _divIntoVS : BinaryUpdateOp[V,S,OpDiv],\n                         _divIntoVV : BinaryUpdateOp[V,V,OpDiv],\n                         _innerVV : BinaryOp[V,V,OpMulInner,S]):MutableInnerProductSpace[S,V] = {\n    new MutableInnerProductSpace[S,V] {\n      def field : Scalar[S] = _field;\n      def numericOps(t: V) = _numericOps(t)\n      def hasValuesMonadic(t: V):HasValuesMonadic[V,S] = _hasValuesMonadic(t)\n      def mapValues: CanMapValues[V,S,S,V] = _mapValues;\n      def zipMapValues: CanZipMapValues[V,S,S,V] = _zipMapValues;\n\n      implicit val zeros: CanCreateZerosLike[V, V] = _zeros\n      implicit val copy: CanCopy[V] = _copy;\n\n//      implicit def negV : UnaryOp[V,OpNeg,V] = _negV;\n\n      implicit def addSV : BinaryOp[S,V,OpAdd,V] = _addSV;\n      implicit def addVS : BinaryOp[V,S,OpAdd,V] = _addVS;\n      implicit def addVV : BinaryOp[V,V,OpAdd,V] = _addVV;\n\n      implicit def subSV : BinaryOp[S,V,OpSub,V] = _subSV;\n      implicit def subVS : BinaryOp[V,S,OpSub,V] = _subVS;\n      implicit def subVV : BinaryOp[V,V,OpSub,V] = _subVV;\n\n      implicit def mulSV : BinaryOp[S,V,OpMul,V] = _mulSV;\n      implicit def mulVS : BinaryOp[V,S,OpMul,V] = _mulVS;\n      implicit def mulVV : BinaryOp[V,V,OpMul,V] = _mulVV;\n\n      implicit def divSV : BinaryOp[S,V,OpDiv,V] = _divSV;\n      implicit def divVS : BinaryOp[V,S,OpDiv,V] = _divVS;\n      implicit def divVV : BinaryOp[V,V,OpDiv,V] = _divVV;\n\n      implicit def innerVV : BinaryOp[V,V,OpMulInner,S] = _innerVV;\n\n      implicit def divIntoVV = _divIntoVV\n      implicit def divIntoVS = _divIntoVS\n\n      implicit def subIntoVV = _subIntoVV\n      implicit def subIntoVS = _subIntoVS\n\n      implicit def addIntoVV = _addIntoVV\n      implicit def addIntoVS = _addIntoVS\n\n      implicit def mulIntoVV = _mulIntoVV\n      implicit def mulIntoVS = _mulIntoVS\n    }\n  }\n\n}"
  },
  {
    "path": "src/main/scala/scalala/operators/codegen/BinaryOpGenerator.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n \npackage scalala;\npackage operators;\npackage codegen;\n\nimport scala.annotation.implicitNotFound;\nimport scala.collection.mutable.HashMap;\n\nimport scalala.scalar.Scalar;\n\ntrait Generator {\n  protected def shorten(m : Manifest[_]) =\n    m.toString.replaceAll(\".*(\\\\$|\\\\.)\",\"\").replaceAll(\"\\\\[|\\\\]\",\"\");\n\n  protected def toImport(m : Manifest[_]) =\n    if (m.erasure.getName.contains(\".\")) \"import \"+m.erasure.getName else \"\";\n  \n  def mkInnerCode : String;\n}\n\nabstract class Function2Generator[A,B,To]\n(implicit ma : Manifest[A], mb : Manifest[B], mt : Manifest[To])\nextends Generator { self =>\n  def className : String;\n\n  def mkClassCode : String = {\n    \"\"\"\n    |  %s\n    |  %s\n    |  %s\n    |  class %s extends ((%s,%s)=>%s) {\n    |    override def apply(a : %s, b : %s) : %s = { %s\n    |    }\n    |    override def toString = \"DynamicallyCompiled\"+getClass.getName\n    |  }\n    \"\"\".stripMargin.format(\n      toImport(ma), toImport(mb), toImport(mt), className, ma, mb, mt,\n      ma, mb, mt, mkInnerCode.replaceAll(\"\\\\$a\",\"a\").replaceAll(\"\\\\$b\",\"b\")\n    );\n  }\n  \n  def prefix(code : String) : Function2Generator[A,B,To] = {\n    new Function2Generator[A,B,To] {\n      override def className = \"Prefixed\"+self.className\n      override def mkInnerCode = code + self.mkInnerCode\n    }\n  }\n  \n  def getInstance =\n    DynamicCompiler.define(className,mkClassCode).newInstance().asInstanceOf[((A,B)=>To)];\n}\n\nabstract class JoinGenerator[A,B,To]\n(implicit ma : Manifest[A], mb : Manifest[B], mt : Manifest[To])\nextends Function2Generator[A,B,To];\n\nclass JoinArrayArrayGenerator[A,B,To](override val className : String)\n(init : String, loop : Function2Generator[A,B,_], done : String)\n(implicit ma : Manifest[A], mb : Manifest[B], mt : Manifest[To])\nextends JoinGenerator[Array[A],Array[B],To] {\n  def mkInnerCode : String = {\n    \"\"\"\n      require($a.length == $b.length)\n      %s\n      var i = 0;\n      while (i < $a.length) {\n        { %s }\n        i += 1;\n      }\n      %s\n    \"\"\".format(\n      init,\n      loop.mkInnerCode.replaceAll(\"\\\\$a\",\"\\\\$a(i)\").replaceAll(\"\\\\$b\",\"\\\\$b(i)\"),\n      done\n    )\n  }\n}\n  \n\n/**\n * Generates inlined, specialized code for BinaryOp[A,B,O,To].\n */\nabstract class BinaryOpGenerator[A,B,O<:OpType,To](\n  implicit ma : Manifest[A], mb : Manifest[B], mo : Manifest[O], mt : Manifest[To])\nextends Function2Generator[A,B,To] {\n  def className() =\n    shorten(mo)+shorten(ma)+shorten(mb);\n  \n  override def mkClassCode : String = {\n    \"\"\"\n    |  import scalala.operators._\n    |  class %s extends BinaryOp[%s,%s,%s,%s] {\n    |    override def opType = %s\n    |    override def apply(a : %s, b : %s) : %s = { %s\n    |    }\n    |    override def toString = \"DynamicallyCompiled\"+getClass.getName\n    |  }\n    \"\"\".stripMargin.format(\n      className, ma, mb, shorten(mo), mt,\n      shorten(mo),\n      ma, mb, mt, mkInnerCode.replaceAll(\"\\\\$a\",\"a\").replaceAll(\"\\\\$b\",\"b\")\n    );\n  }\n  \n  override def getInstance =\n    super.getInstance.asInstanceOf[BinaryOp[A,B,O,To]];\n}\n\nobject BinaryOpGenerator {\n  class BinaryOpScalarScalarInfixGenerator[V1,V2,O<:OpType,RV](val opType : O, symbol : Char)\n  (implicit s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  extends BinaryOpGenerator[V1,V2,O,RV] {\n    def mkInnerCode = \"$a\"+symbol+\"$b\"\n  }\n  \n  implicit def BinaryOpAddScalarScalarGenerator[V1,V2,RV]\n  (implicit s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mr : Manifest[RV])\n  : BinaryOpGenerator[V1,V2,OpAdd,RV] =\n    new BinaryOpScalarScalarInfixGenerator(OpAdd,'+');\n\n  implicit def BinaryOpSubScalarScalarGenerator[V1,V2,RV]\n  (implicit s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mr : Manifest[RV])\n  : BinaryOpGenerator[V1,V2,OpSub,RV] =\n    new BinaryOpScalarScalarInfixGenerator(OpSub,'-');\n  \n  implicit def BinaryOpMulScalarScalarGenerator[V1,V2,RV]\n  (implicit s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mr : Manifest[RV])\n  : BinaryOpGenerator[V1,V2,OpMul,RV] =\n    new BinaryOpScalarScalarInfixGenerator(OpMul,'*');\n  \n  implicit def BinaryOpDivScalarScalarGenerator[V1,V2,RV]\n  (implicit s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mr : Manifest[RV])\n  : BinaryOpGenerator[V1,V2,OpDiv,RV] =\n    new BinaryOpScalarScalarInfixGenerator(OpDiv,'/');\n\n  implicit def BinaryOpArrayArrayGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV],\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[Array[V1],Array[V2],O,Array[RV]]\n  = new BinaryOpGenerator[Array[V1],Array[V2],O,Array[RV]] {\n    def mkInnerCode = \"\"\"\n      require($a.length == $b.length, \"Inputs must be the same length\");\n      var rv = new Array[%s]($a.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = %s;\n        i += 1;\n      }\n      rv;\n    \"\"\".format(mr.toString, op.mkInnerCode.replaceAll(\"\\\\$a\",\"\\\\$a(i)\").replaceAll(\"\\\\$b\",\"\\\\$b(i)\"));\n  }\n  \n  implicit def BinaryOpArrayScalarGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s : Scalar[V2],\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[Array[V1], V2, O, Array[RV]]\n  = new BinaryOpGenerator[Array[V1], V2, O, Array[RV]] {\n    def mkInnerCode = \"\"\"\n      var rv = new Array[%s]($a.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = %s;\n        i += 1;\n      }\n      rv;\n    \"\"\".format(mr.toString, op.mkInnerCode.replaceAll(\"\\\\$a\",\"\\\\$a(i)\"))\n  }\n  \n  implicit def BinaryOpScalarArrayGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s : Scalar[V1],\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[V1, Array[V2], O, Array[RV]]\n  = new BinaryOpGenerator[V1, Array[V2], O, Array[RV]] {\n    def mkInnerCode = \"\"\"\n      var rv = new Array[%s]($b.length);\n      var i = 0;\n      while (i < rv.length) {\n        rv(i) = %s;\n        i += 1;\n      }\n      rv;\n    \"\"\".format(mr.toString, op.mkInnerCode.replaceAll(\"\\\\$b\",\"\\\\$b(i)\"))\n  }\n  \n  \n  \n  import scalala.tensor.dense._;\n  \n//  class JoinDenseVectorDenseVectorGenerator[DV[V]<:DenseVector[V],V1,V2,RV]\n//  (className : String, setup : code :   \n  \n  class BinaryOpDenseVectorDenseVectorGenerator[DV[V]<:DenseVector[V],V1,V2,O<:OpType,RV]\n  (className : String)(implicit op : BinaryOpGenerator[V1,V2,O,RV],\n   s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[DV[V1]], mv2 : Manifest[DV[V2]], mo : Manifest[O], mr : Manifest[DV[RV]])\n  extends BinaryOpGenerator[DV[V1],DV[V2],O,DV[RV]] {\n    def mkInnerCode = \"\"\"\n      require($a.length == $b.length, \"Vectors must have the same length\");\n      val rv = new Array[%s]($a.length);\n      var ia = $a.offset;\n      var ib = $b.offset;\n      var ir = 0;\n      while (ir < rv.length) {\n        rv(ir) = %s;\n        ia += $a.stride;\n        ib += $b.stride;\n        ir += 1;\n      }\n      new %s(rv);\n    \"\"\".format(sr.manifest.toString,\n      op.mkInnerCode.replaceAll(\"\\\\$a\",\"\\\\$a.data(ia)\").replaceAll(\"\\\\$b\",\"\\\\$b.data(ib)\"),\n      className)\n  }\n\n  implicit def BinaryOpDenseVectorColDenseVectorColGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s1 : Scalar[V1],\n   s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[DenseVectorCol[V1],DenseVectorCol[V2],O,DenseVectorCol[RV]]\n  = new BinaryOpDenseVectorDenseVectorGenerator[DenseVectorCol,V1,V2,O,RV](\n    classOf[DenseVectorCol[_]].getName)\n\n  implicit def BinaryOpDenseVectorRowDenseVectorRowGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s1 : Scalar[V1],\n   s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[DenseVectorRow[V1],DenseVectorRow[V2],O,DenseVectorRow[RV]]\n  = new BinaryOpDenseVectorDenseVectorGenerator[DenseVectorRow,V1,V2,O,RV](\n    classOf[DenseVectorRow[_]].getName)\n\n  class BinaryOpDenseVectorScalarGenerator[DV[V]<:DenseVector[V],V1,V2,O<:OpType,RV]\n  (className : String)(implicit op : BinaryOpGenerator[V1,V2,O,RV],\n   s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[DV[V1]], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[DV[RV]])\n  extends BinaryOpGenerator[DV[V1],V2,O,DV[RV]] {\n    def mkInnerCode = \"\"\"\n      val rv = new Array[%s]($a.length);\n      var ia = $a.offset;\n      var ir = 0;\n      while (ir < rv.length) {\n        rv(ir) = %s;\n        ia += $a.stride;\n        ir += 1;\n      }\n      new %s(rv);\n    \"\"\".format(sr.manifest.toString, op.mkInnerCode.replaceAll(\"\\\\$a\",\"\\\\$a.data(ia)\"),className)\n  }\n\n  implicit def BinaryOpDenseVectorColScalarGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s1 : Scalar[V1],\n   s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[DenseVectorCol[V1],V2,O,DenseVectorCol[RV]]\n  = new BinaryOpDenseVectorScalarGenerator[DenseVectorCol,V1,V2,O,RV](\n    classOf[DenseVectorCol[_]].getName)\n\n  implicit def BinaryOpDenseVectorRowScalarGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s1 : Scalar[V1],\n   s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[DenseVectorRow[V1],V2,O,DenseVectorRow[RV]]\n  = new BinaryOpDenseVectorScalarGenerator[DenseVectorRow,V1,V2,O,RV](\n    classOf[DenseVectorRow[_]].getName)\n\n  class BinaryOpScalarDenseVectorGenerator[DV[V]<:DenseVector[V],V1,V2,O<:OpType,RV]\n  (className : String)(implicit op : BinaryOpGenerator[V1,V2,O,RV],\n   s1 : Scalar[V1], s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[DV[V2]], mo : Manifest[O], mr : Manifest[DV[RV]])\n  extends BinaryOpGenerator[V1,DV[V2],O,DV[RV]] {\n    def mkInnerCode = \"\"\"\n      val rv = new Array[%s]($b.length);\n      var ib = $b.offset;\n      var ir = 0;\n      while (ir < rv.length) {\n        rv(ir) = %s;\n        ib += $b.stride;\n        ir += 1;\n      }\n      new %s(rv);\n    \"\"\".format(sr.manifest.toString, op.mkInnerCode.replaceAll(\"\\\\$b\",\"\\\\$b.data(ib)\"),className)\n  }\n\n  implicit def BinaryOpScalarDenseVectorColGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s1 : Scalar[V1],\n   s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[V1,DenseVectorCol[V2],O,DenseVectorCol[RV]]\n  = new BinaryOpScalarDenseVectorGenerator[DenseVectorCol,V1,V2,O,RV](\n    classOf[DenseVectorCol[_]].getName)\n\n  implicit def BinaryOpScalarDenseVectorRowGenerator[V1,V2,O<:OpType,RV]\n  (implicit op : BinaryOpGenerator[V1,V2,O,RV], s1 : Scalar[V1],\n   s2 : Scalar[V2], sr : Scalar[RV], c1 : V1=>RV, c2 : V2=>RV,\n   mv1 : Manifest[V1], mv2 : Manifest[V2], mo : Manifest[O], mr : Manifest[RV])\n  : BinaryOpGenerator[V1,DenseVectorRow[V2],O,DenseVectorRow[RV]]\n  = new BinaryOpScalarDenseVectorGenerator[DenseVectorRow,V1,V2,O,RV](\n    classOf[DenseVectorRow[_]].getName)\n}\n\nobject GeneratedRegistryEntries {\n import scalala.tensor.dense._;\n  \n  def main(args : Array[String]) {\n    val ops = Array(\"OpAdd\",\"OpSub\",\"OpMul\",\"OpDiv\")\n    val scalars = Array(\"Int\",\"Long\",\"Float\",\"Double\")\n    val tensors = Array(\"Array\",\"DenseVectorRow\",\"DenseVectorCol\")\n    \n    // returns the scalar result of combining the two operands\n    def sr(s1 : String, s2 : String) =\n      if (scalars.indexOf(s1) < scalars.indexOf(s2)) s2 else s1;\n    \n    val opsTensorTensorSame = \n      for (t <- tensors; s1 <- scalars; s2 <- scalars; op <- ops) yield\n        \"Registry.register[%s[%s],%s[%s],%s,%s[%s]]\".format(t,s1,t,s2,op,t,sr(s1,s2))\n    \n    val opsTensorScalar =\n      for (t <- tensors; s1 <- scalars; s2 <- scalars; op <- ops) yield\n        \"Registry.register[%s[%s],%s,%s,%s[%s]]\".format(t,s1,s2,op,t,sr(s1,s2));\n      \n    val opsScalarTensor =\n      for (t <- tensors; s1 <- scalars; s2 <- scalars; op <- ops) yield\n        \"Registry.register[%s,%s[%s],%s,%s[%s]]\".format(s1,t,s2,op,t,sr(s1,s2));\n    \n    println(\"\"\"\n      |  def init() {\n      |    initTensorTensorSame();\n      |    initTensorScalar();\n      |    initScalarTensor();\n      |  }\n      |\n      |  def initTensorTensorSame() {\n      |    %s\n      |  }\n      |\n      |  def initTensorScalar() {\n      |    %s\n      |  }\n      |\n      |  def initScalarTensor() {\n      |    %s\n      |  }\n      \"\"\".stripMargin.format(\n        opsTensorTensorSame.mkString(\"\\n    \"),\n        opsTensorScalar.mkString(\"\\n    \"),\n        opsScalarTensor.mkString(\"\\n    \")));\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/codegen/DynamicCompiler.scala",
    "content": "/*\n * Copyright 2010 Twitter, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may\n * not use this file except in compliance with the License. You may obtain\n * a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage scalala\npackage operators.codegen\n\nimport java.io.File\nimport java.util.jar.JarFile\nimport scala.collection.mutable\nimport scala.io.Source\nimport scala.tools.nsc.{Global, Settings}\nimport scala.tools.nsc.interpreter.AbstractFileClassLoader\nimport scala.tools.nsc.io.{AbstractFile, VirtualDirectory}\nimport scala.tools.nsc.reporters.AbstractReporter\nimport scala.tools.nsc.util.{BatchSourceFile, Position}\n\nimport java.net.URLClassLoader\n\n/**\n * Class for dynamically defining classes and loading them at runtime.\n * Based on on Twitter's Eval helper class with modifications by dramage.\n *\n * This class is pretty slow to initialize, actually.\n *\n * https://github.com/twitter/util/blob/master/util-eval/src/main/scala/com/twitter/util/Eval.scala\n */\nobject DynamicCompiler {\n  private val compiler = new StringCompiler(0, None)\n\n  def define(className : String, code : String) : Class[_] =\n    compiler(code, className);\n  \n  private lazy val compilerPath = try {\n    jarPathOfClass(\"scala.tools.nsc.Interpreter\")\n  } catch {\n    case e =>\n      throw new RuntimeException(\"Unable to load scala interpreter from classpath (scala-compiler jar is missing?)\", e)\n  }\n\n  private lazy val libPath = try {\n    jarPathOfClass(\"scala.ScalaObject\")\n  } catch {\n    case e =>\n      throw new RuntimeException(\"Unable to load scala base object from classpath (scala-library jar is missing?)\", e)\n  }\n\n  /*\n   * For a given FQ classname, trick the resource finder into telling us the containing jar.\n   */\n  private def jarPathOfClass(className: String) = try {\n    val resource = className.split('.').mkString(\"/\", \"/\", \".class\")\n    val path = getClass.getResource(resource).getPath\n    val indexOfFile = path.indexOf(\"file:\") + 5\n    val indexOfSeparator = path.lastIndexOf('!')\n    List(path.substring(indexOfFile, indexOfSeparator))\n  }\n  \n  /*\n   * Try to guess our app's classpath.\n   * This is probably fragile.\n   */\n  private lazy val impliedClassPath: List[String] = {\n    val parent =\n      if (this.getClass.getClassLoader.isInstanceOf[URLClassLoader]) {\n        this.getClass.getClassLoader.asInstanceOf[URLClassLoader]\n      } else {\n        ClassLoader.getSystemClassLoader.asInstanceOf[URLClassLoader]\n      }\n      \n    val currentClassPath = parent.getURLs.\n      map(_.toString).filter(_.startsWith(\"file:\")).map(_.substring(5)).toList\n\n    // if there's just one thing in the classpath, and it's a jar, assume an executable jar.\n    currentClassPath ::: (if (currentClassPath.size == 1 && currentClassPath(0).endsWith(\".jar\")) {\n      val jarFile = currentClassPath(0)\n      val relativeRoot = new File(jarFile).getParentFile()\n      val nestedClassPath = new JarFile(jarFile).getManifest.getMainAttributes.getValue(\"Class-Path\")\n      if (nestedClassPath eq null) {\n        Nil\n      } else {\n        nestedClassPath.split(\" \").map { f => new File(relativeRoot, f).getAbsolutePath }.toList\n      }\n    } else {\n      Nil\n    })\n  }\n  \n  /**\n   * Dynamic scala compiler. Lots of (slow) state is created, so it may be advantageous to keep\n   * around one of these and reuse it.\n   */\n  private class StringCompiler(lineOffset: Int, targetDir: Option[File]) {\n    val target = targetDir match {\n      case Some(dir) => AbstractFile.getDirectory(dir)\n      case None => new VirtualDirectory(\"(memory)\", None)\n    }\n\n    val cache = new mutable.HashMap[String, Class[_]]()\n\n    val settings = new Settings\n    settings.deprecation.value = true // enable detailed deprecation warnings\n    settings.unchecked.value = true // enable detailed unchecked warnings\n    settings.outputDirs.setSingleOutput(target)\n\n    val pathList = compilerPath ::: libPath\n    settings.bootclasspath.value = pathList.mkString(File.pathSeparator)\n    settings.classpath.value = (pathList ::: impliedClassPath).mkString(File.pathSeparator)\n\n    val reporter = new AbstractReporter {\n      val settings = StringCompiler.this.settings\n      val messages = new mutable.ListBuffer[List[String]]\n\n      def display(pos: Position, message: String, severity: Severity) {\n        severity.count += 1\n        val severityName = severity match {\n          case ERROR   => \"error: \"\n          case WARNING => \"warning: \"\n          case _ => \"\"\n        }\n        messages += (severityName + \"line \" + (pos.line - lineOffset) + \": \" + message) ::\n          (if (pos.isDefined) {\n            pos.inUltimateSource(pos.source).lineContent.stripLineEnd ::\n              (\" \" * (pos.column - 1) + \"^\") ::\n              Nil\n          } else {\n            Nil\n          })\n      }\n\n      def displayPrompt {\n        // no.\n      }\n\n      override def reset {\n        super.reset\n        messages.clear()\n      }\n    }\n\n    val global = new Global(settings, reporter)\n\n    /*\n     * Class loader for finding classes compiled by this StringCompiler.\n     * After each reset, this class loader will not be able to find old compiled classes.\n     */\n    var classLoader = new AbstractFileClassLoader(target, this.getClass.getClassLoader)\n\n    def reset() {\n      targetDir match {\n        case None => {\n          target.asInstanceOf[VirtualDirectory].clear\n        }\n        case Some(t) => {\n          target.foreach { abstractFile =>\n            if (abstractFile.file == null || abstractFile.file.getName.endsWith(\".class\")) {\n              abstractFile.delete\n            }\n          }\n        }\n      }\n      cache.clear()\n      reporter.reset\n      classLoader = new AbstractFileClassLoader(target, this.getClass.getClassLoader)\n    }\n\n    object Debug {\n      val enabled =\n        System.getProperty(\"eval.debug\") != null\n\n      def printWithLineNumbers(code: String) {\n        printf(\"Code follows (%d bytes)\\n\", code.length)\n\n        var numLines = 0\n        code.lines foreach { line: String =>\n          numLines += 1\n          println(numLines.toString.padTo(5, ' ') + \"| \" + line)\n        }\n      }\n    }\n\n    def findClass(className: String): Option[Class[_]] = {\n      synchronized {\n        cache.get(className).orElse {\n          try {\n            val cls = classLoader.loadClass(className)\n            cache(className) = cls\n            Some(cls)\n          } catch {\n            case e: ClassNotFoundException => None\n          }\n        }\n      }\n    }\n\n    /**\n     * Compile scala code. It can be found using the above class loader.\n     */\n    def apply(code: String) {\n      if (Debug.enabled)\n        Debug.printWithLineNumbers(code)\n\n      // if you're looking for the performance hit, it's 1/2 this line...\n      val compiler = new global.Run\n      val sourceFiles = List(new BatchSourceFile(\"(inline)\", code))\n      // ...and 1/2 this line:\n      compiler.compileSources(sourceFiles)\n\n      if (reporter.hasErrors || reporter.WARNING.count > 0) {\n        throw new CompilerException(reporter.messages.toList)\n      }\n    }\n\n    /**\n     * Compile a new class, load it, and return it. Thread-safe.\n     */\n    def apply(code: String, className: String, resetState: Boolean = true): Class[_] = {\n      synchronized {\n        if (resetState) reset()\n        findClass(className).getOrElse {\n          apply(code)\n          findClass(className).get\n        }\n      }\n    }\n  }\n\n  class CompilerException(val messages: List[List[String]]) extends Exception(\n    \"Compiler exception \" + messages.map(_.mkString(\"\\n\")).mkString(\"\\n\"))\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/operators/codegen/GeneratedBinaryOp.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n \npackage scalala;\npackage operators;\npackage codegen;\n\nimport scalala.tensor.dense._;\n\n\nclass GeneratedBinaryOp[A, B, O<:OpType, To](override val opType : O)\n(implicit a : Manifest[A], b : Manifest[B], op : Manifest[O], to : Manifest[To],\n gen : BinaryOpGenerator[A,B,O,To])\nextends BinaryOp[A,B,O,To] {\n  lazy val instance = gen.getInstance\n\n  override def apply(a : A, b : B) =\n    instance(a,b);\n  \n  override def toString =\n    gen.toString;\n}\n\nobject GeneratedBinaryOpDefinitions {\n  def main(args : Array[String]) {\n    val ops = Array(\"OpAdd\",\"OpSub\",\"OpMul\",\"OpDiv\")\n    val scalars = Array(\"Int\",\"Long\",\"Float\",\"Double\")\n    val tensors = Array(\"Array\",\"DenseVectorRow\",\"DenseVectorCol\")\n    \n    // returns the scalar result of combining the two operands\n    def sr(s1 : String, s2 : String) =\n      if (scalars.indexOf(s1) < scalars.indexOf(s2)) s2 else s1;\n    \n    val opsTensorTensorSame = \n      for (t <- tensors; s1 <- scalars; s2 <- scalars; op <- ops) yield \"\"\"\n        |  implicit object %s%s%s%s%s extends GeneratedBinaryOp[%s[%s],%s[%s],%s,%s[%s]](%s)\n        |  BinaryOpRegistry.register[%s[%s],%s[%s],%s,%s[%s]]\n        \"\"\".stripMargin.format(op,t,s1,t,s2,t,s1,t,s2,op,t,sr(s1,s2),op,t,s1,t,s2,op,t,sr(s1,s2))\n\n    val opsTensorScalar =\n      for (t <- tensors; s1 <- scalars; s2 <- scalars; op <- ops) yield\n        \"implicit object %s%s%s%s extends GeneratedBinaryOp[%s[%s],%s,%s,%s[%s]](%s)\".\n          format(op,t,s1,s2,t,s1,s2,op,t,sr(s1,s2),op)\n      \n    val opsScalarTensor =\n      for (t <- tensors; s1 <- scalars; s2 <- scalars; op <- ops) yield\n        \"implicit object %s%s%s%s extends GeneratedBinaryOp[%s,%s[%s],%s,%s[%s]](%s)\".\n          format(op,s1,t,s2,s1,t,s2,op,t,sr(s1,s2),op);\n\n    for (line <- opsTensorTensorSame ++ opsTensorScalar ++ opsScalarTensor) {\n      println(\"  \"+line)\n    }\n  }\n}\n\nobject GeneratedBinaryOps {\n  \n  def init() {}\n  \n  implicit object OpAddArrayIntArrayInt extends GeneratedBinaryOp[Array[Int],Array[Int],OpAdd,Array[Int]](OpAdd)\n  BinaryOpRegistry.register[Array[Int],Array[Int],OpAdd,Array[Int]]\n        \n  \n  implicit object OpSubArrayIntArrayInt extends GeneratedBinaryOp[Array[Int],Array[Int],OpSub,Array[Int]](OpSub)\n  BinaryOpRegistry.register[Array[Int],Array[Int],OpSub,Array[Int]]\n        \n  \n  implicit object OpMulArrayIntArrayInt extends GeneratedBinaryOp[Array[Int],Array[Int],OpMul,Array[Int]](OpMul)\n  BinaryOpRegistry.register[Array[Int],Array[Int],OpMul,Array[Int]]\n        \n  \n  implicit object OpDivArrayIntArrayInt extends GeneratedBinaryOp[Array[Int],Array[Int],OpDiv,Array[Int]](OpDiv)\n  BinaryOpRegistry.register[Array[Int],Array[Int],OpDiv,Array[Int]]\n        \n  \n  implicit object OpAddArrayIntArrayLong extends GeneratedBinaryOp[Array[Int],Array[Long],OpAdd,Array[Long]](OpAdd)\n  BinaryOpRegistry.register[Array[Int],Array[Long],OpAdd,Array[Long]]\n        \n  \n  implicit object OpSubArrayIntArrayLong extends GeneratedBinaryOp[Array[Int],Array[Long],OpSub,Array[Long]](OpSub)\n  BinaryOpRegistry.register[Array[Int],Array[Long],OpSub,Array[Long]]\n        \n  \n  implicit object OpMulArrayIntArrayLong extends GeneratedBinaryOp[Array[Int],Array[Long],OpMul,Array[Long]](OpMul)\n  BinaryOpRegistry.register[Array[Int],Array[Long],OpMul,Array[Long]]\n        \n  \n  implicit object OpDivArrayIntArrayLong extends GeneratedBinaryOp[Array[Int],Array[Long],OpDiv,Array[Long]](OpDiv)\n  BinaryOpRegistry.register[Array[Int],Array[Long],OpDiv,Array[Long]]\n        \n  \n  implicit object OpAddArrayIntArrayFloat extends GeneratedBinaryOp[Array[Int],Array[Float],OpAdd,Array[Float]](OpAdd)\n  BinaryOpRegistry.register[Array[Int],Array[Float],OpAdd,Array[Float]]\n        \n  \n  implicit object OpSubArrayIntArrayFloat extends GeneratedBinaryOp[Array[Int],Array[Float],OpSub,Array[Float]](OpSub)\n  BinaryOpRegistry.register[Array[Int],Array[Float],OpSub,Array[Float]]\n        \n  \n  implicit object OpMulArrayIntArrayFloat extends GeneratedBinaryOp[Array[Int],Array[Float],OpMul,Array[Float]](OpMul)\n  BinaryOpRegistry.register[Array[Int],Array[Float],OpMul,Array[Float]]\n        \n  \n  implicit object OpDivArrayIntArrayFloat extends GeneratedBinaryOp[Array[Int],Array[Float],OpDiv,Array[Float]](OpDiv)\n  BinaryOpRegistry.register[Array[Int],Array[Float],OpDiv,Array[Float]]\n        \n  \n  implicit object OpAddArrayIntArrayDouble extends GeneratedBinaryOp[Array[Int],Array[Double],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Int],Array[Double],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayIntArrayDouble extends GeneratedBinaryOp[Array[Int],Array[Double],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Int],Array[Double],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayIntArrayDouble extends GeneratedBinaryOp[Array[Int],Array[Double],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Int],Array[Double],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayIntArrayDouble extends GeneratedBinaryOp[Array[Int],Array[Double],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Int],Array[Double],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddArrayLongArrayInt extends GeneratedBinaryOp[Array[Long],Array[Int],OpAdd,Array[Long]](OpAdd)\n  BinaryOpRegistry.register[Array[Long],Array[Int],OpAdd,Array[Long]]\n        \n  \n  implicit object OpSubArrayLongArrayInt extends GeneratedBinaryOp[Array[Long],Array[Int],OpSub,Array[Long]](OpSub)\n  BinaryOpRegistry.register[Array[Long],Array[Int],OpSub,Array[Long]]\n        \n  \n  implicit object OpMulArrayLongArrayInt extends GeneratedBinaryOp[Array[Long],Array[Int],OpMul,Array[Long]](OpMul)\n  BinaryOpRegistry.register[Array[Long],Array[Int],OpMul,Array[Long]]\n        \n  \n  implicit object OpDivArrayLongArrayInt extends GeneratedBinaryOp[Array[Long],Array[Int],OpDiv,Array[Long]](OpDiv)\n  BinaryOpRegistry.register[Array[Long],Array[Int],OpDiv,Array[Long]]\n        \n  \n  implicit object OpAddArrayLongArrayLong extends GeneratedBinaryOp[Array[Long],Array[Long],OpAdd,Array[Long]](OpAdd)\n  BinaryOpRegistry.register[Array[Long],Array[Long],OpAdd,Array[Long]]\n        \n  \n  implicit object OpSubArrayLongArrayLong extends GeneratedBinaryOp[Array[Long],Array[Long],OpSub,Array[Long]](OpSub)\n  BinaryOpRegistry.register[Array[Long],Array[Long],OpSub,Array[Long]]\n        \n  \n  implicit object OpMulArrayLongArrayLong extends GeneratedBinaryOp[Array[Long],Array[Long],OpMul,Array[Long]](OpMul)\n  BinaryOpRegistry.register[Array[Long],Array[Long],OpMul,Array[Long]]\n        \n  \n  implicit object OpDivArrayLongArrayLong extends GeneratedBinaryOp[Array[Long],Array[Long],OpDiv,Array[Long]](OpDiv)\n  BinaryOpRegistry.register[Array[Long],Array[Long],OpDiv,Array[Long]]\n        \n  \n  implicit object OpAddArrayLongArrayFloat extends GeneratedBinaryOp[Array[Long],Array[Float],OpAdd,Array[Float]](OpAdd)\n  BinaryOpRegistry.register[Array[Long],Array[Float],OpAdd,Array[Float]]\n        \n  \n  implicit object OpSubArrayLongArrayFloat extends GeneratedBinaryOp[Array[Long],Array[Float],OpSub,Array[Float]](OpSub)\n  BinaryOpRegistry.register[Array[Long],Array[Float],OpSub,Array[Float]]\n        \n  \n  implicit object OpMulArrayLongArrayFloat extends GeneratedBinaryOp[Array[Long],Array[Float],OpMul,Array[Float]](OpMul)\n  BinaryOpRegistry.register[Array[Long],Array[Float],OpMul,Array[Float]]\n        \n  \n  implicit object OpDivArrayLongArrayFloat extends GeneratedBinaryOp[Array[Long],Array[Float],OpDiv,Array[Float]](OpDiv)\n  BinaryOpRegistry.register[Array[Long],Array[Float],OpDiv,Array[Float]]\n        \n  \n  implicit object OpAddArrayLongArrayDouble extends GeneratedBinaryOp[Array[Long],Array[Double],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Long],Array[Double],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayLongArrayDouble extends GeneratedBinaryOp[Array[Long],Array[Double],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Long],Array[Double],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayLongArrayDouble extends GeneratedBinaryOp[Array[Long],Array[Double],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Long],Array[Double],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayLongArrayDouble extends GeneratedBinaryOp[Array[Long],Array[Double],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Long],Array[Double],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddArrayFloatArrayInt extends GeneratedBinaryOp[Array[Float],Array[Int],OpAdd,Array[Float]](OpAdd)\n  BinaryOpRegistry.register[Array[Float],Array[Int],OpAdd,Array[Float]]\n        \n  \n  implicit object OpSubArrayFloatArrayInt extends GeneratedBinaryOp[Array[Float],Array[Int],OpSub,Array[Float]](OpSub)\n  BinaryOpRegistry.register[Array[Float],Array[Int],OpSub,Array[Float]]\n        \n  \n  implicit object OpMulArrayFloatArrayInt extends GeneratedBinaryOp[Array[Float],Array[Int],OpMul,Array[Float]](OpMul)\n  BinaryOpRegistry.register[Array[Float],Array[Int],OpMul,Array[Float]]\n        \n  \n  implicit object OpDivArrayFloatArrayInt extends GeneratedBinaryOp[Array[Float],Array[Int],OpDiv,Array[Float]](OpDiv)\n  BinaryOpRegistry.register[Array[Float],Array[Int],OpDiv,Array[Float]]\n        \n  \n  implicit object OpAddArrayFloatArrayLong extends GeneratedBinaryOp[Array[Float],Array[Long],OpAdd,Array[Float]](OpAdd)\n  BinaryOpRegistry.register[Array[Float],Array[Long],OpAdd,Array[Float]]\n        \n  \n  implicit object OpSubArrayFloatArrayLong extends GeneratedBinaryOp[Array[Float],Array[Long],OpSub,Array[Float]](OpSub)\n  BinaryOpRegistry.register[Array[Float],Array[Long],OpSub,Array[Float]]\n        \n  \n  implicit object OpMulArrayFloatArrayLong extends GeneratedBinaryOp[Array[Float],Array[Long],OpMul,Array[Float]](OpMul)\n  BinaryOpRegistry.register[Array[Float],Array[Long],OpMul,Array[Float]]\n        \n  \n  implicit object OpDivArrayFloatArrayLong extends GeneratedBinaryOp[Array[Float],Array[Long],OpDiv,Array[Float]](OpDiv)\n  BinaryOpRegistry.register[Array[Float],Array[Long],OpDiv,Array[Float]]\n        \n  \n  implicit object OpAddArrayFloatArrayFloat extends GeneratedBinaryOp[Array[Float],Array[Float],OpAdd,Array[Float]](OpAdd)\n  BinaryOpRegistry.register[Array[Float],Array[Float],OpAdd,Array[Float]]\n        \n  \n  implicit object OpSubArrayFloatArrayFloat extends GeneratedBinaryOp[Array[Float],Array[Float],OpSub,Array[Float]](OpSub)\n  BinaryOpRegistry.register[Array[Float],Array[Float],OpSub,Array[Float]]\n        \n  \n  implicit object OpMulArrayFloatArrayFloat extends GeneratedBinaryOp[Array[Float],Array[Float],OpMul,Array[Float]](OpMul)\n  BinaryOpRegistry.register[Array[Float],Array[Float],OpMul,Array[Float]]\n        \n  \n  implicit object OpDivArrayFloatArrayFloat extends GeneratedBinaryOp[Array[Float],Array[Float],OpDiv,Array[Float]](OpDiv)\n  BinaryOpRegistry.register[Array[Float],Array[Float],OpDiv,Array[Float]]\n        \n  \n  implicit object OpAddArrayFloatArrayDouble extends GeneratedBinaryOp[Array[Float],Array[Double],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Float],Array[Double],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayFloatArrayDouble extends GeneratedBinaryOp[Array[Float],Array[Double],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Float],Array[Double],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayFloatArrayDouble extends GeneratedBinaryOp[Array[Float],Array[Double],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Float],Array[Double],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayFloatArrayDouble extends GeneratedBinaryOp[Array[Float],Array[Double],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Float],Array[Double],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddArrayDoubleArrayInt extends GeneratedBinaryOp[Array[Double],Array[Int],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Double],Array[Int],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayDoubleArrayInt extends GeneratedBinaryOp[Array[Double],Array[Int],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Double],Array[Int],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayDoubleArrayInt extends GeneratedBinaryOp[Array[Double],Array[Int],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Double],Array[Int],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayDoubleArrayInt extends GeneratedBinaryOp[Array[Double],Array[Int],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Double],Array[Int],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddArrayDoubleArrayLong extends GeneratedBinaryOp[Array[Double],Array[Long],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Double],Array[Long],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayDoubleArrayLong extends GeneratedBinaryOp[Array[Double],Array[Long],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Double],Array[Long],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayDoubleArrayLong extends GeneratedBinaryOp[Array[Double],Array[Long],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Double],Array[Long],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayDoubleArrayLong extends GeneratedBinaryOp[Array[Double],Array[Long],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Double],Array[Long],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddArrayDoubleArrayFloat extends GeneratedBinaryOp[Array[Double],Array[Float],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Double],Array[Float],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayDoubleArrayFloat extends GeneratedBinaryOp[Array[Double],Array[Float],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Double],Array[Float],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayDoubleArrayFloat extends GeneratedBinaryOp[Array[Double],Array[Float],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Double],Array[Float],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayDoubleArrayFloat extends GeneratedBinaryOp[Array[Double],Array[Float],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Double],Array[Float],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddArrayDoubleArrayDouble extends GeneratedBinaryOp[Array[Double],Array[Double],OpAdd,Array[Double]](OpAdd)\n  BinaryOpRegistry.register[Array[Double],Array[Double],OpAdd,Array[Double]]\n        \n  \n  implicit object OpSubArrayDoubleArrayDouble extends GeneratedBinaryOp[Array[Double],Array[Double],OpSub,Array[Double]](OpSub)\n  BinaryOpRegistry.register[Array[Double],Array[Double],OpSub,Array[Double]]\n        \n  \n  implicit object OpMulArrayDoubleArrayDouble extends GeneratedBinaryOp[Array[Double],Array[Double],OpMul,Array[Double]](OpMul)\n  BinaryOpRegistry.register[Array[Double],Array[Double],OpMul,Array[Double]]\n        \n  \n  implicit object OpDivArrayDoubleArrayDouble extends GeneratedBinaryOp[Array[Double],Array[Double],OpDiv,Array[Double]](OpDiv)\n  BinaryOpRegistry.register[Array[Double],Array[Double],OpDiv,Array[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowIntDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Int],OpAdd,DenseVectorRow[Int]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Int],OpAdd,DenseVectorRow[Int]]\n        \n  \n  implicit object OpSubDenseVectorRowIntDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Int],OpSub,DenseVectorRow[Int]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Int],OpSub,DenseVectorRow[Int]]\n        \n  \n  implicit object OpMulDenseVectorRowIntDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Int],OpMul,DenseVectorRow[Int]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Int],OpMul,DenseVectorRow[Int]]\n        \n  \n  implicit object OpDivDenseVectorRowIntDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Int],OpDiv,DenseVectorRow[Int]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Int],OpDiv,DenseVectorRow[Int]]\n        \n  \n  implicit object OpAddDenseVectorRowIntDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Long],OpAdd,DenseVectorRow[Long]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Long],OpAdd,DenseVectorRow[Long]]\n        \n  \n  implicit object OpSubDenseVectorRowIntDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Long],OpSub,DenseVectorRow[Long]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Long],OpSub,DenseVectorRow[Long]]\n        \n  \n  implicit object OpMulDenseVectorRowIntDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Long],OpMul,DenseVectorRow[Long]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Long],OpMul,DenseVectorRow[Long]]\n        \n  \n  implicit object OpDivDenseVectorRowIntDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Long],OpDiv,DenseVectorRow[Long]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Long],OpDiv,DenseVectorRow[Long]]\n        \n  \n  implicit object OpAddDenseVectorRowIntDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]]\n        \n  \n  implicit object OpSubDenseVectorRowIntDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Float],OpSub,DenseVectorRow[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Float],OpSub,DenseVectorRow[Float]]\n        \n  \n  implicit object OpMulDenseVectorRowIntDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Float],OpMul,DenseVectorRow[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Float],OpMul,DenseVectorRow[Float]]\n        \n  \n  implicit object OpDivDenseVectorRowIntDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]]\n        \n  \n  implicit object OpAddDenseVectorRowIntDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowIntDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowIntDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowIntDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Int],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Int],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowLongDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Int],OpAdd,DenseVectorRow[Long]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Int],OpAdd,DenseVectorRow[Long]]\n        \n  \n  implicit object OpSubDenseVectorRowLongDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Int],OpSub,DenseVectorRow[Long]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Int],OpSub,DenseVectorRow[Long]]\n        \n  \n  implicit object OpMulDenseVectorRowLongDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Int],OpMul,DenseVectorRow[Long]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Int],OpMul,DenseVectorRow[Long]]\n        \n  \n  implicit object OpDivDenseVectorRowLongDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Int],OpDiv,DenseVectorRow[Long]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Int],OpDiv,DenseVectorRow[Long]]\n        \n  \n  implicit object OpAddDenseVectorRowLongDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Long],OpAdd,DenseVectorRow[Long]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Long],OpAdd,DenseVectorRow[Long]]\n        \n  \n  implicit object OpSubDenseVectorRowLongDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Long],OpSub,DenseVectorRow[Long]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Long],OpSub,DenseVectorRow[Long]]\n        \n  \n  implicit object OpMulDenseVectorRowLongDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Long],OpMul,DenseVectorRow[Long]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Long],OpMul,DenseVectorRow[Long]]\n        \n  \n  implicit object OpDivDenseVectorRowLongDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Long],OpDiv,DenseVectorRow[Long]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Long],OpDiv,DenseVectorRow[Long]]\n        \n  \n  implicit object OpAddDenseVectorRowLongDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]]\n        \n  \n  implicit object OpSubDenseVectorRowLongDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Float],OpSub,DenseVectorRow[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Float],OpSub,DenseVectorRow[Float]]\n        \n  \n  implicit object OpMulDenseVectorRowLongDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Float],OpMul,DenseVectorRow[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Float],OpMul,DenseVectorRow[Float]]\n        \n  \n  implicit object OpDivDenseVectorRowLongDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]]\n        \n  \n  implicit object OpAddDenseVectorRowLongDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowLongDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowLongDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowLongDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Long],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Long],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowFloatDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Int],OpAdd,DenseVectorRow[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Int],OpAdd,DenseVectorRow[Float]]\n        \n  \n  implicit object OpSubDenseVectorRowFloatDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Int],OpSub,DenseVectorRow[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Int],OpSub,DenseVectorRow[Float]]\n        \n  \n  implicit object OpMulDenseVectorRowFloatDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Int],OpMul,DenseVectorRow[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Int],OpMul,DenseVectorRow[Float]]\n        \n  \n  implicit object OpDivDenseVectorRowFloatDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Int],OpDiv,DenseVectorRow[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Int],OpDiv,DenseVectorRow[Float]]\n        \n  \n  implicit object OpAddDenseVectorRowFloatDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Long],OpAdd,DenseVectorRow[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Long],OpAdd,DenseVectorRow[Float]]\n        \n  \n  implicit object OpSubDenseVectorRowFloatDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Long],OpSub,DenseVectorRow[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Long],OpSub,DenseVectorRow[Float]]\n        \n  \n  implicit object OpMulDenseVectorRowFloatDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Long],OpMul,DenseVectorRow[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Long],OpMul,DenseVectorRow[Float]]\n        \n  \n  implicit object OpDivDenseVectorRowFloatDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Long],OpDiv,DenseVectorRow[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Long],OpDiv,DenseVectorRow[Float]]\n        \n  \n  implicit object OpAddDenseVectorRowFloatDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]]\n        \n  \n  implicit object OpSubDenseVectorRowFloatDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Float],OpSub,DenseVectorRow[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Float],OpSub,DenseVectorRow[Float]]\n        \n  \n  implicit object OpMulDenseVectorRowFloatDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Float],OpMul,DenseVectorRow[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Float],OpMul,DenseVectorRow[Float]]\n        \n  \n  implicit object OpDivDenseVectorRowFloatDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]]\n        \n  \n  implicit object OpAddDenseVectorRowFloatDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowFloatDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowFloatDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowFloatDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Float],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Float],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowDoubleDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Int],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Int],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowDoubleDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Int],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Int],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowDoubleDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Int],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Int],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowDoubleDenseVectorRowInt extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Int],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Int],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowDoubleDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Long],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Long],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowDoubleDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Long],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Long],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowDoubleDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Long],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Long],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowDoubleDenseVectorRowLong extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Long],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Long],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowDoubleDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Float],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Float],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowDoubleDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Float],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Float],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowDoubleDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Float],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Float],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowDoubleDenseVectorRowFloat extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Float],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Float],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorRowDoubleDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]]\n        \n  \n  implicit object OpSubDenseVectorRowDoubleDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Double],OpSub,DenseVectorRow[Double]]\n        \n  \n  implicit object OpMulDenseVectorRowDoubleDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Double],OpMul,DenseVectorRow[Double]]\n        \n  \n  implicit object OpDivDenseVectorRowDoubleDenseVectorRowDouble extends GeneratedBinaryOp[DenseVectorRow[Double],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorRow[Double],DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]]\n        \n  \n  implicit object OpAddDenseVectorColIntDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Int],OpAdd,DenseVectorCol[Int]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Int],OpAdd,DenseVectorCol[Int]]\n        \n  \n  implicit object OpSubDenseVectorColIntDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Int],OpSub,DenseVectorCol[Int]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Int],OpSub,DenseVectorCol[Int]]\n        \n  \n  implicit object OpMulDenseVectorColIntDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Int],OpMul,DenseVectorCol[Int]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Int],OpMul,DenseVectorCol[Int]]\n        \n  \n  implicit object OpDivDenseVectorColIntDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Int],OpDiv,DenseVectorCol[Int]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Int],OpDiv,DenseVectorCol[Int]]\n        \n  \n  implicit object OpAddDenseVectorColIntDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Long],OpAdd,DenseVectorCol[Long]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Long],OpAdd,DenseVectorCol[Long]]\n        \n  \n  implicit object OpSubDenseVectorColIntDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Long],OpSub,DenseVectorCol[Long]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Long],OpSub,DenseVectorCol[Long]]\n        \n  \n  implicit object OpMulDenseVectorColIntDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Long],OpMul,DenseVectorCol[Long]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Long],OpMul,DenseVectorCol[Long]]\n        \n  \n  implicit object OpDivDenseVectorColIntDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Long],OpDiv,DenseVectorCol[Long]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Long],OpDiv,DenseVectorCol[Long]]\n        \n  \n  implicit object OpAddDenseVectorColIntDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]]\n        \n  \n  implicit object OpSubDenseVectorColIntDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Float],OpSub,DenseVectorCol[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Float],OpSub,DenseVectorCol[Float]]\n        \n  \n  implicit object OpMulDenseVectorColIntDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Float],OpMul,DenseVectorCol[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Float],OpMul,DenseVectorCol[Float]]\n        \n  \n  implicit object OpDivDenseVectorColIntDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]]\n        \n  \n  implicit object OpAddDenseVectorColIntDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColIntDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColIntDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColIntDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Int],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Int],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]]\n        \n  \n  implicit object OpAddDenseVectorColLongDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Int],OpAdd,DenseVectorCol[Long]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Int],OpAdd,DenseVectorCol[Long]]\n        \n  \n  implicit object OpSubDenseVectorColLongDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Int],OpSub,DenseVectorCol[Long]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Int],OpSub,DenseVectorCol[Long]]\n        \n  \n  implicit object OpMulDenseVectorColLongDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Int],OpMul,DenseVectorCol[Long]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Int],OpMul,DenseVectorCol[Long]]\n        \n  \n  implicit object OpDivDenseVectorColLongDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Int],OpDiv,DenseVectorCol[Long]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Int],OpDiv,DenseVectorCol[Long]]\n        \n  \n  implicit object OpAddDenseVectorColLongDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Long],OpAdd,DenseVectorCol[Long]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Long],OpAdd,DenseVectorCol[Long]]\n        \n  \n  implicit object OpSubDenseVectorColLongDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Long],OpSub,DenseVectorCol[Long]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Long],OpSub,DenseVectorCol[Long]]\n        \n  \n  implicit object OpMulDenseVectorColLongDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Long],OpMul,DenseVectorCol[Long]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Long],OpMul,DenseVectorCol[Long]]\n        \n  \n  implicit object OpDivDenseVectorColLongDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Long],OpDiv,DenseVectorCol[Long]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Long],OpDiv,DenseVectorCol[Long]]\n        \n  \n  implicit object OpAddDenseVectorColLongDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]]\n        \n  \n  implicit object OpSubDenseVectorColLongDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Float],OpSub,DenseVectorCol[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Float],OpSub,DenseVectorCol[Float]]\n        \n  \n  implicit object OpMulDenseVectorColLongDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Float],OpMul,DenseVectorCol[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Float],OpMul,DenseVectorCol[Float]]\n        \n  \n  implicit object OpDivDenseVectorColLongDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]]\n        \n  \n  implicit object OpAddDenseVectorColLongDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColLongDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColLongDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColLongDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Long],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Long],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]]\n        \n  \n  implicit object OpAddDenseVectorColFloatDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Int],OpAdd,DenseVectorCol[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Int],OpAdd,DenseVectorCol[Float]]\n        \n  \n  implicit object OpSubDenseVectorColFloatDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Int],OpSub,DenseVectorCol[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Int],OpSub,DenseVectorCol[Float]]\n        \n  \n  implicit object OpMulDenseVectorColFloatDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Int],OpMul,DenseVectorCol[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Int],OpMul,DenseVectorCol[Float]]\n        \n  \n  implicit object OpDivDenseVectorColFloatDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Int],OpDiv,DenseVectorCol[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Int],OpDiv,DenseVectorCol[Float]]\n        \n  \n  implicit object OpAddDenseVectorColFloatDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Long],OpAdd,DenseVectorCol[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Long],OpAdd,DenseVectorCol[Float]]\n        \n  \n  implicit object OpSubDenseVectorColFloatDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Long],OpSub,DenseVectorCol[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Long],OpSub,DenseVectorCol[Float]]\n        \n  \n  implicit object OpMulDenseVectorColFloatDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Long],OpMul,DenseVectorCol[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Long],OpMul,DenseVectorCol[Float]]\n        \n  \n  implicit object OpDivDenseVectorColFloatDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Long],OpDiv,DenseVectorCol[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Long],OpDiv,DenseVectorCol[Float]]\n        \n  \n  implicit object OpAddDenseVectorColFloatDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]]\n        \n  \n  implicit object OpSubDenseVectorColFloatDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Float],OpSub,DenseVectorCol[Float]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Float],OpSub,DenseVectorCol[Float]]\n        \n  \n  implicit object OpMulDenseVectorColFloatDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Float],OpMul,DenseVectorCol[Float]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Float],OpMul,DenseVectorCol[Float]]\n        \n  \n  implicit object OpDivDenseVectorColFloatDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]]\n        \n  \n  implicit object OpAddDenseVectorColFloatDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColFloatDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColFloatDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColFloatDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Float],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Float],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]]\n        \n  \n  implicit object OpAddDenseVectorColDoubleDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Int],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Int],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColDoubleDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Int],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Int],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColDoubleDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Int],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Int],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColDoubleDenseVectorColInt extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Int],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Int],OpDiv,DenseVectorCol[Double]]\n        \n  \n  implicit object OpAddDenseVectorColDoubleDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Long],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Long],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColDoubleDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Long],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Long],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColDoubleDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Long],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Long],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColDoubleDenseVectorColLong extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Long],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Long],OpDiv,DenseVectorCol[Double]]\n        \n  \n  implicit object OpAddDenseVectorColDoubleDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Float],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Float],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColDoubleDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Float],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Float],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColDoubleDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Float],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Float],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColDoubleDenseVectorColFloat extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Float],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Float],OpDiv,DenseVectorCol[Double]]\n        \n  \n  implicit object OpAddDenseVectorColDoubleDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]]\n        \n  \n  implicit object OpSubDenseVectorColDoubleDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Double],OpSub,DenseVectorCol[Double]]\n        \n  \n  implicit object OpMulDenseVectorColDoubleDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Double],OpMul,DenseVectorCol[Double]]\n        \n  \n  implicit object OpDivDenseVectorColDoubleDenseVectorColDouble extends GeneratedBinaryOp[DenseVectorCol[Double],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  BinaryOpRegistry.register[DenseVectorCol[Double],DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]]\n        \n  implicit object OpAddArrayIntInt extends GeneratedBinaryOp[Array[Int],Int,OpAdd,Array[Int]](OpAdd)\n  implicit object OpSubArrayIntInt extends GeneratedBinaryOp[Array[Int],Int,OpSub,Array[Int]](OpSub)\n  implicit object OpMulArrayIntInt extends GeneratedBinaryOp[Array[Int],Int,OpMul,Array[Int]](OpMul)\n  implicit object OpDivArrayIntInt extends GeneratedBinaryOp[Array[Int],Int,OpDiv,Array[Int]](OpDiv)\n  implicit object OpAddArrayIntLong extends GeneratedBinaryOp[Array[Int],Long,OpAdd,Array[Long]](OpAdd)\n  implicit object OpSubArrayIntLong extends GeneratedBinaryOp[Array[Int],Long,OpSub,Array[Long]](OpSub)\n  implicit object OpMulArrayIntLong extends GeneratedBinaryOp[Array[Int],Long,OpMul,Array[Long]](OpMul)\n  implicit object OpDivArrayIntLong extends GeneratedBinaryOp[Array[Int],Long,OpDiv,Array[Long]](OpDiv)\n  implicit object OpAddArrayIntFloat extends GeneratedBinaryOp[Array[Int],Float,OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubArrayIntFloat extends GeneratedBinaryOp[Array[Int],Float,OpSub,Array[Float]](OpSub)\n  implicit object OpMulArrayIntFloat extends GeneratedBinaryOp[Array[Int],Float,OpMul,Array[Float]](OpMul)\n  implicit object OpDivArrayIntFloat extends GeneratedBinaryOp[Array[Int],Float,OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddArrayIntDouble extends GeneratedBinaryOp[Array[Int],Double,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayIntDouble extends GeneratedBinaryOp[Array[Int],Double,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayIntDouble extends GeneratedBinaryOp[Array[Int],Double,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayIntDouble extends GeneratedBinaryOp[Array[Int],Double,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddArrayLongInt extends GeneratedBinaryOp[Array[Long],Int,OpAdd,Array[Long]](OpAdd)\n  implicit object OpSubArrayLongInt extends GeneratedBinaryOp[Array[Long],Int,OpSub,Array[Long]](OpSub)\n  implicit object OpMulArrayLongInt extends GeneratedBinaryOp[Array[Long],Int,OpMul,Array[Long]](OpMul)\n  implicit object OpDivArrayLongInt extends GeneratedBinaryOp[Array[Long],Int,OpDiv,Array[Long]](OpDiv)\n  implicit object OpAddArrayLongLong extends GeneratedBinaryOp[Array[Long],Long,OpAdd,Array[Long]](OpAdd)\n  implicit object OpSubArrayLongLong extends GeneratedBinaryOp[Array[Long],Long,OpSub,Array[Long]](OpSub)\n  implicit object OpMulArrayLongLong extends GeneratedBinaryOp[Array[Long],Long,OpMul,Array[Long]](OpMul)\n  implicit object OpDivArrayLongLong extends GeneratedBinaryOp[Array[Long],Long,OpDiv,Array[Long]](OpDiv)\n  implicit object OpAddArrayLongFloat extends GeneratedBinaryOp[Array[Long],Float,OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubArrayLongFloat extends GeneratedBinaryOp[Array[Long],Float,OpSub,Array[Float]](OpSub)\n  implicit object OpMulArrayLongFloat extends GeneratedBinaryOp[Array[Long],Float,OpMul,Array[Float]](OpMul)\n  implicit object OpDivArrayLongFloat extends GeneratedBinaryOp[Array[Long],Float,OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddArrayLongDouble extends GeneratedBinaryOp[Array[Long],Double,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayLongDouble extends GeneratedBinaryOp[Array[Long],Double,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayLongDouble extends GeneratedBinaryOp[Array[Long],Double,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayLongDouble extends GeneratedBinaryOp[Array[Long],Double,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddArrayFloatInt extends GeneratedBinaryOp[Array[Float],Int,OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubArrayFloatInt extends GeneratedBinaryOp[Array[Float],Int,OpSub,Array[Float]](OpSub)\n  implicit object OpMulArrayFloatInt extends GeneratedBinaryOp[Array[Float],Int,OpMul,Array[Float]](OpMul)\n  implicit object OpDivArrayFloatInt extends GeneratedBinaryOp[Array[Float],Int,OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddArrayFloatLong extends GeneratedBinaryOp[Array[Float],Long,OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubArrayFloatLong extends GeneratedBinaryOp[Array[Float],Long,OpSub,Array[Float]](OpSub)\n  implicit object OpMulArrayFloatLong extends GeneratedBinaryOp[Array[Float],Long,OpMul,Array[Float]](OpMul)\n  implicit object OpDivArrayFloatLong extends GeneratedBinaryOp[Array[Float],Long,OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddArrayFloatFloat extends GeneratedBinaryOp[Array[Float],Float,OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubArrayFloatFloat extends GeneratedBinaryOp[Array[Float],Float,OpSub,Array[Float]](OpSub)\n  implicit object OpMulArrayFloatFloat extends GeneratedBinaryOp[Array[Float],Float,OpMul,Array[Float]](OpMul)\n  implicit object OpDivArrayFloatFloat extends GeneratedBinaryOp[Array[Float],Float,OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddArrayFloatDouble extends GeneratedBinaryOp[Array[Float],Double,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayFloatDouble extends GeneratedBinaryOp[Array[Float],Double,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayFloatDouble extends GeneratedBinaryOp[Array[Float],Double,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayFloatDouble extends GeneratedBinaryOp[Array[Float],Double,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddArrayDoubleInt extends GeneratedBinaryOp[Array[Double],Int,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayDoubleInt extends GeneratedBinaryOp[Array[Double],Int,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayDoubleInt extends GeneratedBinaryOp[Array[Double],Int,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayDoubleInt extends GeneratedBinaryOp[Array[Double],Int,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddArrayDoubleLong extends GeneratedBinaryOp[Array[Double],Long,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayDoubleLong extends GeneratedBinaryOp[Array[Double],Long,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayDoubleLong extends GeneratedBinaryOp[Array[Double],Long,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayDoubleLong extends GeneratedBinaryOp[Array[Double],Long,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddArrayDoubleFloat extends GeneratedBinaryOp[Array[Double],Float,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayDoubleFloat extends GeneratedBinaryOp[Array[Double],Float,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayDoubleFloat extends GeneratedBinaryOp[Array[Double],Float,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayDoubleFloat extends GeneratedBinaryOp[Array[Double],Float,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddArrayDoubleDouble extends GeneratedBinaryOp[Array[Double],Double,OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubArrayDoubleDouble extends GeneratedBinaryOp[Array[Double],Double,OpSub,Array[Double]](OpSub)\n  implicit object OpMulArrayDoubleDouble extends GeneratedBinaryOp[Array[Double],Double,OpMul,Array[Double]](OpMul)\n  implicit object OpDivArrayDoubleDouble extends GeneratedBinaryOp[Array[Double],Double,OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowIntInt extends GeneratedBinaryOp[DenseVectorRow[Int],Int,OpAdd,DenseVectorRow[Int]](OpAdd)\n  implicit object OpSubDenseVectorRowIntInt extends GeneratedBinaryOp[DenseVectorRow[Int],Int,OpSub,DenseVectorRow[Int]](OpSub)\n  implicit object OpMulDenseVectorRowIntInt extends GeneratedBinaryOp[DenseVectorRow[Int],Int,OpMul,DenseVectorRow[Int]](OpMul)\n  implicit object OpDivDenseVectorRowIntInt extends GeneratedBinaryOp[DenseVectorRow[Int],Int,OpDiv,DenseVectorRow[Int]](OpDiv)\n  implicit object OpAddDenseVectorRowIntLong extends GeneratedBinaryOp[DenseVectorRow[Int],Long,OpAdd,DenseVectorRow[Long]](OpAdd)\n  implicit object OpSubDenseVectorRowIntLong extends GeneratedBinaryOp[DenseVectorRow[Int],Long,OpSub,DenseVectorRow[Long]](OpSub)\n  implicit object OpMulDenseVectorRowIntLong extends GeneratedBinaryOp[DenseVectorRow[Int],Long,OpMul,DenseVectorRow[Long]](OpMul)\n  implicit object OpDivDenseVectorRowIntLong extends GeneratedBinaryOp[DenseVectorRow[Int],Long,OpDiv,DenseVectorRow[Long]](OpDiv)\n  implicit object OpAddDenseVectorRowIntFloat extends GeneratedBinaryOp[DenseVectorRow[Int],Float,OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubDenseVectorRowIntFloat extends GeneratedBinaryOp[DenseVectorRow[Int],Float,OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulDenseVectorRowIntFloat extends GeneratedBinaryOp[DenseVectorRow[Int],Float,OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivDenseVectorRowIntFloat extends GeneratedBinaryOp[DenseVectorRow[Int],Float,OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddDenseVectorRowIntDouble extends GeneratedBinaryOp[DenseVectorRow[Int],Double,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowIntDouble extends GeneratedBinaryOp[DenseVectorRow[Int],Double,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowIntDouble extends GeneratedBinaryOp[DenseVectorRow[Int],Double,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowIntDouble extends GeneratedBinaryOp[DenseVectorRow[Int],Double,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowLongInt extends GeneratedBinaryOp[DenseVectorRow[Long],Int,OpAdd,DenseVectorRow[Long]](OpAdd)\n  implicit object OpSubDenseVectorRowLongInt extends GeneratedBinaryOp[DenseVectorRow[Long],Int,OpSub,DenseVectorRow[Long]](OpSub)\n  implicit object OpMulDenseVectorRowLongInt extends GeneratedBinaryOp[DenseVectorRow[Long],Int,OpMul,DenseVectorRow[Long]](OpMul)\n  implicit object OpDivDenseVectorRowLongInt extends GeneratedBinaryOp[DenseVectorRow[Long],Int,OpDiv,DenseVectorRow[Long]](OpDiv)\n  implicit object OpAddDenseVectorRowLongLong extends GeneratedBinaryOp[DenseVectorRow[Long],Long,OpAdd,DenseVectorRow[Long]](OpAdd)\n  implicit object OpSubDenseVectorRowLongLong extends GeneratedBinaryOp[DenseVectorRow[Long],Long,OpSub,DenseVectorRow[Long]](OpSub)\n  implicit object OpMulDenseVectorRowLongLong extends GeneratedBinaryOp[DenseVectorRow[Long],Long,OpMul,DenseVectorRow[Long]](OpMul)\n  implicit object OpDivDenseVectorRowLongLong extends GeneratedBinaryOp[DenseVectorRow[Long],Long,OpDiv,DenseVectorRow[Long]](OpDiv)\n  implicit object OpAddDenseVectorRowLongFloat extends GeneratedBinaryOp[DenseVectorRow[Long],Float,OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubDenseVectorRowLongFloat extends GeneratedBinaryOp[DenseVectorRow[Long],Float,OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulDenseVectorRowLongFloat extends GeneratedBinaryOp[DenseVectorRow[Long],Float,OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivDenseVectorRowLongFloat extends GeneratedBinaryOp[DenseVectorRow[Long],Float,OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddDenseVectorRowLongDouble extends GeneratedBinaryOp[DenseVectorRow[Long],Double,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowLongDouble extends GeneratedBinaryOp[DenseVectorRow[Long],Double,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowLongDouble extends GeneratedBinaryOp[DenseVectorRow[Long],Double,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowLongDouble extends GeneratedBinaryOp[DenseVectorRow[Long],Double,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowFloatInt extends GeneratedBinaryOp[DenseVectorRow[Float],Int,OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubDenseVectorRowFloatInt extends GeneratedBinaryOp[DenseVectorRow[Float],Int,OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulDenseVectorRowFloatInt extends GeneratedBinaryOp[DenseVectorRow[Float],Int,OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivDenseVectorRowFloatInt extends GeneratedBinaryOp[DenseVectorRow[Float],Int,OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddDenseVectorRowFloatLong extends GeneratedBinaryOp[DenseVectorRow[Float],Long,OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubDenseVectorRowFloatLong extends GeneratedBinaryOp[DenseVectorRow[Float],Long,OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulDenseVectorRowFloatLong extends GeneratedBinaryOp[DenseVectorRow[Float],Long,OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivDenseVectorRowFloatLong extends GeneratedBinaryOp[DenseVectorRow[Float],Long,OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddDenseVectorRowFloatFloat extends GeneratedBinaryOp[DenseVectorRow[Float],Float,OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubDenseVectorRowFloatFloat extends GeneratedBinaryOp[DenseVectorRow[Float],Float,OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulDenseVectorRowFloatFloat extends GeneratedBinaryOp[DenseVectorRow[Float],Float,OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivDenseVectorRowFloatFloat extends GeneratedBinaryOp[DenseVectorRow[Float],Float,OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddDenseVectorRowFloatDouble extends GeneratedBinaryOp[DenseVectorRow[Float],Double,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowFloatDouble extends GeneratedBinaryOp[DenseVectorRow[Float],Double,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowFloatDouble extends GeneratedBinaryOp[DenseVectorRow[Float],Double,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowFloatDouble extends GeneratedBinaryOp[DenseVectorRow[Float],Double,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowDoubleInt extends GeneratedBinaryOp[DenseVectorRow[Double],Int,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowDoubleInt extends GeneratedBinaryOp[DenseVectorRow[Double],Int,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowDoubleInt extends GeneratedBinaryOp[DenseVectorRow[Double],Int,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowDoubleInt extends GeneratedBinaryOp[DenseVectorRow[Double],Int,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowDoubleLong extends GeneratedBinaryOp[DenseVectorRow[Double],Long,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowDoubleLong extends GeneratedBinaryOp[DenseVectorRow[Double],Long,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowDoubleLong extends GeneratedBinaryOp[DenseVectorRow[Double],Long,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowDoubleLong extends GeneratedBinaryOp[DenseVectorRow[Double],Long,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowDoubleFloat extends GeneratedBinaryOp[DenseVectorRow[Double],Float,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowDoubleFloat extends GeneratedBinaryOp[DenseVectorRow[Double],Float,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowDoubleFloat extends GeneratedBinaryOp[DenseVectorRow[Double],Float,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowDoubleFloat extends GeneratedBinaryOp[DenseVectorRow[Double],Float,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorRowDoubleDouble extends GeneratedBinaryOp[DenseVectorRow[Double],Double,OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDenseVectorRowDoubleDouble extends GeneratedBinaryOp[DenseVectorRow[Double],Double,OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDenseVectorRowDoubleDouble extends GeneratedBinaryOp[DenseVectorRow[Double],Double,OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDenseVectorRowDoubleDouble extends GeneratedBinaryOp[DenseVectorRow[Double],Double,OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDenseVectorColIntInt extends GeneratedBinaryOp[DenseVectorCol[Int],Int,OpAdd,DenseVectorCol[Int]](OpAdd)\n  implicit object OpSubDenseVectorColIntInt extends GeneratedBinaryOp[DenseVectorCol[Int],Int,OpSub,DenseVectorCol[Int]](OpSub)\n  implicit object OpMulDenseVectorColIntInt extends GeneratedBinaryOp[DenseVectorCol[Int],Int,OpMul,DenseVectorCol[Int]](OpMul)\n  implicit object OpDivDenseVectorColIntInt extends GeneratedBinaryOp[DenseVectorCol[Int],Int,OpDiv,DenseVectorCol[Int]](OpDiv)\n  implicit object OpAddDenseVectorColIntLong extends GeneratedBinaryOp[DenseVectorCol[Int],Long,OpAdd,DenseVectorCol[Long]](OpAdd)\n  implicit object OpSubDenseVectorColIntLong extends GeneratedBinaryOp[DenseVectorCol[Int],Long,OpSub,DenseVectorCol[Long]](OpSub)\n  implicit object OpMulDenseVectorColIntLong extends GeneratedBinaryOp[DenseVectorCol[Int],Long,OpMul,DenseVectorCol[Long]](OpMul)\n  implicit object OpDivDenseVectorColIntLong extends GeneratedBinaryOp[DenseVectorCol[Int],Long,OpDiv,DenseVectorCol[Long]](OpDiv)\n  implicit object OpAddDenseVectorColIntFloat extends GeneratedBinaryOp[DenseVectorCol[Int],Float,OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubDenseVectorColIntFloat extends GeneratedBinaryOp[DenseVectorCol[Int],Float,OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulDenseVectorColIntFloat extends GeneratedBinaryOp[DenseVectorCol[Int],Float,OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivDenseVectorColIntFloat extends GeneratedBinaryOp[DenseVectorCol[Int],Float,OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddDenseVectorColIntDouble extends GeneratedBinaryOp[DenseVectorCol[Int],Double,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColIntDouble extends GeneratedBinaryOp[DenseVectorCol[Int],Double,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColIntDouble extends GeneratedBinaryOp[DenseVectorCol[Int],Double,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColIntDouble extends GeneratedBinaryOp[DenseVectorCol[Int],Double,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDenseVectorColLongInt extends GeneratedBinaryOp[DenseVectorCol[Long],Int,OpAdd,DenseVectorCol[Long]](OpAdd)\n  implicit object OpSubDenseVectorColLongInt extends GeneratedBinaryOp[DenseVectorCol[Long],Int,OpSub,DenseVectorCol[Long]](OpSub)\n  implicit object OpMulDenseVectorColLongInt extends GeneratedBinaryOp[DenseVectorCol[Long],Int,OpMul,DenseVectorCol[Long]](OpMul)\n  implicit object OpDivDenseVectorColLongInt extends GeneratedBinaryOp[DenseVectorCol[Long],Int,OpDiv,DenseVectorCol[Long]](OpDiv)\n  implicit object OpAddDenseVectorColLongLong extends GeneratedBinaryOp[DenseVectorCol[Long],Long,OpAdd,DenseVectorCol[Long]](OpAdd)\n  implicit object OpSubDenseVectorColLongLong extends GeneratedBinaryOp[DenseVectorCol[Long],Long,OpSub,DenseVectorCol[Long]](OpSub)\n  implicit object OpMulDenseVectorColLongLong extends GeneratedBinaryOp[DenseVectorCol[Long],Long,OpMul,DenseVectorCol[Long]](OpMul)\n  implicit object OpDivDenseVectorColLongLong extends GeneratedBinaryOp[DenseVectorCol[Long],Long,OpDiv,DenseVectorCol[Long]](OpDiv)\n  implicit object OpAddDenseVectorColLongFloat extends GeneratedBinaryOp[DenseVectorCol[Long],Float,OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubDenseVectorColLongFloat extends GeneratedBinaryOp[DenseVectorCol[Long],Float,OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulDenseVectorColLongFloat extends GeneratedBinaryOp[DenseVectorCol[Long],Float,OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivDenseVectorColLongFloat extends GeneratedBinaryOp[DenseVectorCol[Long],Float,OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddDenseVectorColLongDouble extends GeneratedBinaryOp[DenseVectorCol[Long],Double,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColLongDouble extends GeneratedBinaryOp[DenseVectorCol[Long],Double,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColLongDouble extends GeneratedBinaryOp[DenseVectorCol[Long],Double,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColLongDouble extends GeneratedBinaryOp[DenseVectorCol[Long],Double,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDenseVectorColFloatInt extends GeneratedBinaryOp[DenseVectorCol[Float],Int,OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubDenseVectorColFloatInt extends GeneratedBinaryOp[DenseVectorCol[Float],Int,OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulDenseVectorColFloatInt extends GeneratedBinaryOp[DenseVectorCol[Float],Int,OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivDenseVectorColFloatInt extends GeneratedBinaryOp[DenseVectorCol[Float],Int,OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddDenseVectorColFloatLong extends GeneratedBinaryOp[DenseVectorCol[Float],Long,OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubDenseVectorColFloatLong extends GeneratedBinaryOp[DenseVectorCol[Float],Long,OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulDenseVectorColFloatLong extends GeneratedBinaryOp[DenseVectorCol[Float],Long,OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivDenseVectorColFloatLong extends GeneratedBinaryOp[DenseVectorCol[Float],Long,OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddDenseVectorColFloatFloat extends GeneratedBinaryOp[DenseVectorCol[Float],Float,OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubDenseVectorColFloatFloat extends GeneratedBinaryOp[DenseVectorCol[Float],Float,OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulDenseVectorColFloatFloat extends GeneratedBinaryOp[DenseVectorCol[Float],Float,OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivDenseVectorColFloatFloat extends GeneratedBinaryOp[DenseVectorCol[Float],Float,OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddDenseVectorColFloatDouble extends GeneratedBinaryOp[DenseVectorCol[Float],Double,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColFloatDouble extends GeneratedBinaryOp[DenseVectorCol[Float],Double,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColFloatDouble extends GeneratedBinaryOp[DenseVectorCol[Float],Double,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColFloatDouble extends GeneratedBinaryOp[DenseVectorCol[Float],Double,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDenseVectorColDoubleInt extends GeneratedBinaryOp[DenseVectorCol[Double],Int,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColDoubleInt extends GeneratedBinaryOp[DenseVectorCol[Double],Int,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColDoubleInt extends GeneratedBinaryOp[DenseVectorCol[Double],Int,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColDoubleInt extends GeneratedBinaryOp[DenseVectorCol[Double],Int,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDenseVectorColDoubleLong extends GeneratedBinaryOp[DenseVectorCol[Double],Long,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColDoubleLong extends GeneratedBinaryOp[DenseVectorCol[Double],Long,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColDoubleLong extends GeneratedBinaryOp[DenseVectorCol[Double],Long,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColDoubleLong extends GeneratedBinaryOp[DenseVectorCol[Double],Long,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDenseVectorColDoubleFloat extends GeneratedBinaryOp[DenseVectorCol[Double],Float,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColDoubleFloat extends GeneratedBinaryOp[DenseVectorCol[Double],Float,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColDoubleFloat extends GeneratedBinaryOp[DenseVectorCol[Double],Float,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColDoubleFloat extends GeneratedBinaryOp[DenseVectorCol[Double],Float,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDenseVectorColDoubleDouble extends GeneratedBinaryOp[DenseVectorCol[Double],Double,OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDenseVectorColDoubleDouble extends GeneratedBinaryOp[DenseVectorCol[Double],Double,OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDenseVectorColDoubleDouble extends GeneratedBinaryOp[DenseVectorCol[Double],Double,OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDenseVectorColDoubleDouble extends GeneratedBinaryOp[DenseVectorCol[Double],Double,OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddIntArrayInt extends GeneratedBinaryOp[Int,Array[Int],OpAdd,Array[Int]](OpAdd)\n  implicit object OpSubIntArrayInt extends GeneratedBinaryOp[Int,Array[Int],OpSub,Array[Int]](OpSub)\n  implicit object OpMulIntArrayInt extends GeneratedBinaryOp[Int,Array[Int],OpMul,Array[Int]](OpMul)\n  implicit object OpDivIntArrayInt extends GeneratedBinaryOp[Int,Array[Int],OpDiv,Array[Int]](OpDiv)\n  implicit object OpAddIntArrayLong extends GeneratedBinaryOp[Int,Array[Long],OpAdd,Array[Long]](OpAdd)\n  implicit object OpSubIntArrayLong extends GeneratedBinaryOp[Int,Array[Long],OpSub,Array[Long]](OpSub)\n  implicit object OpMulIntArrayLong extends GeneratedBinaryOp[Int,Array[Long],OpMul,Array[Long]](OpMul)\n  implicit object OpDivIntArrayLong extends GeneratedBinaryOp[Int,Array[Long],OpDiv,Array[Long]](OpDiv)\n  implicit object OpAddIntArrayFloat extends GeneratedBinaryOp[Int,Array[Float],OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubIntArrayFloat extends GeneratedBinaryOp[Int,Array[Float],OpSub,Array[Float]](OpSub)\n  implicit object OpMulIntArrayFloat extends GeneratedBinaryOp[Int,Array[Float],OpMul,Array[Float]](OpMul)\n  implicit object OpDivIntArrayFloat extends GeneratedBinaryOp[Int,Array[Float],OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddIntArrayDouble extends GeneratedBinaryOp[Int,Array[Double],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubIntArrayDouble extends GeneratedBinaryOp[Int,Array[Double],OpSub,Array[Double]](OpSub)\n  implicit object OpMulIntArrayDouble extends GeneratedBinaryOp[Int,Array[Double],OpMul,Array[Double]](OpMul)\n  implicit object OpDivIntArrayDouble extends GeneratedBinaryOp[Int,Array[Double],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddLongArrayInt extends GeneratedBinaryOp[Long,Array[Int],OpAdd,Array[Long]](OpAdd)\n  implicit object OpSubLongArrayInt extends GeneratedBinaryOp[Long,Array[Int],OpSub,Array[Long]](OpSub)\n  implicit object OpMulLongArrayInt extends GeneratedBinaryOp[Long,Array[Int],OpMul,Array[Long]](OpMul)\n  implicit object OpDivLongArrayInt extends GeneratedBinaryOp[Long,Array[Int],OpDiv,Array[Long]](OpDiv)\n  implicit object OpAddLongArrayLong extends GeneratedBinaryOp[Long,Array[Long],OpAdd,Array[Long]](OpAdd)\n  implicit object OpSubLongArrayLong extends GeneratedBinaryOp[Long,Array[Long],OpSub,Array[Long]](OpSub)\n  implicit object OpMulLongArrayLong extends GeneratedBinaryOp[Long,Array[Long],OpMul,Array[Long]](OpMul)\n  implicit object OpDivLongArrayLong extends GeneratedBinaryOp[Long,Array[Long],OpDiv,Array[Long]](OpDiv)\n  implicit object OpAddLongArrayFloat extends GeneratedBinaryOp[Long,Array[Float],OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubLongArrayFloat extends GeneratedBinaryOp[Long,Array[Float],OpSub,Array[Float]](OpSub)\n  implicit object OpMulLongArrayFloat extends GeneratedBinaryOp[Long,Array[Float],OpMul,Array[Float]](OpMul)\n  implicit object OpDivLongArrayFloat extends GeneratedBinaryOp[Long,Array[Float],OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddLongArrayDouble extends GeneratedBinaryOp[Long,Array[Double],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubLongArrayDouble extends GeneratedBinaryOp[Long,Array[Double],OpSub,Array[Double]](OpSub)\n  implicit object OpMulLongArrayDouble extends GeneratedBinaryOp[Long,Array[Double],OpMul,Array[Double]](OpMul)\n  implicit object OpDivLongArrayDouble extends GeneratedBinaryOp[Long,Array[Double],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddFloatArrayInt extends GeneratedBinaryOp[Float,Array[Int],OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubFloatArrayInt extends GeneratedBinaryOp[Float,Array[Int],OpSub,Array[Float]](OpSub)\n  implicit object OpMulFloatArrayInt extends GeneratedBinaryOp[Float,Array[Int],OpMul,Array[Float]](OpMul)\n  implicit object OpDivFloatArrayInt extends GeneratedBinaryOp[Float,Array[Int],OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddFloatArrayLong extends GeneratedBinaryOp[Float,Array[Long],OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubFloatArrayLong extends GeneratedBinaryOp[Float,Array[Long],OpSub,Array[Float]](OpSub)\n  implicit object OpMulFloatArrayLong extends GeneratedBinaryOp[Float,Array[Long],OpMul,Array[Float]](OpMul)\n  implicit object OpDivFloatArrayLong extends GeneratedBinaryOp[Float,Array[Long],OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddFloatArrayFloat extends GeneratedBinaryOp[Float,Array[Float],OpAdd,Array[Float]](OpAdd)\n  implicit object OpSubFloatArrayFloat extends GeneratedBinaryOp[Float,Array[Float],OpSub,Array[Float]](OpSub)\n  implicit object OpMulFloatArrayFloat extends GeneratedBinaryOp[Float,Array[Float],OpMul,Array[Float]](OpMul)\n  implicit object OpDivFloatArrayFloat extends GeneratedBinaryOp[Float,Array[Float],OpDiv,Array[Float]](OpDiv)\n  implicit object OpAddFloatArrayDouble extends GeneratedBinaryOp[Float,Array[Double],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubFloatArrayDouble extends GeneratedBinaryOp[Float,Array[Double],OpSub,Array[Double]](OpSub)\n  implicit object OpMulFloatArrayDouble extends GeneratedBinaryOp[Float,Array[Double],OpMul,Array[Double]](OpMul)\n  implicit object OpDivFloatArrayDouble extends GeneratedBinaryOp[Float,Array[Double],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddDoubleArrayInt extends GeneratedBinaryOp[Double,Array[Int],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubDoubleArrayInt extends GeneratedBinaryOp[Double,Array[Int],OpSub,Array[Double]](OpSub)\n  implicit object OpMulDoubleArrayInt extends GeneratedBinaryOp[Double,Array[Int],OpMul,Array[Double]](OpMul)\n  implicit object OpDivDoubleArrayInt extends GeneratedBinaryOp[Double,Array[Int],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddDoubleArrayLong extends GeneratedBinaryOp[Double,Array[Long],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubDoubleArrayLong extends GeneratedBinaryOp[Double,Array[Long],OpSub,Array[Double]](OpSub)\n  implicit object OpMulDoubleArrayLong extends GeneratedBinaryOp[Double,Array[Long],OpMul,Array[Double]](OpMul)\n  implicit object OpDivDoubleArrayLong extends GeneratedBinaryOp[Double,Array[Long],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddDoubleArrayFloat extends GeneratedBinaryOp[Double,Array[Float],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubDoubleArrayFloat extends GeneratedBinaryOp[Double,Array[Float],OpSub,Array[Double]](OpSub)\n  implicit object OpMulDoubleArrayFloat extends GeneratedBinaryOp[Double,Array[Float],OpMul,Array[Double]](OpMul)\n  implicit object OpDivDoubleArrayFloat extends GeneratedBinaryOp[Double,Array[Float],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddDoubleArrayDouble extends GeneratedBinaryOp[Double,Array[Double],OpAdd,Array[Double]](OpAdd)\n  implicit object OpSubDoubleArrayDouble extends GeneratedBinaryOp[Double,Array[Double],OpSub,Array[Double]](OpSub)\n  implicit object OpMulDoubleArrayDouble extends GeneratedBinaryOp[Double,Array[Double],OpMul,Array[Double]](OpMul)\n  implicit object OpDivDoubleArrayDouble extends GeneratedBinaryOp[Double,Array[Double],OpDiv,Array[Double]](OpDiv)\n  implicit object OpAddIntDenseVectorRowInt extends GeneratedBinaryOp[Int,DenseVectorRow[Int],OpAdd,DenseVectorRow[Int]](OpAdd)\n  implicit object OpSubIntDenseVectorRowInt extends GeneratedBinaryOp[Int,DenseVectorRow[Int],OpSub,DenseVectorRow[Int]](OpSub)\n  implicit object OpMulIntDenseVectorRowInt extends GeneratedBinaryOp[Int,DenseVectorRow[Int],OpMul,DenseVectorRow[Int]](OpMul)\n  implicit object OpDivIntDenseVectorRowInt extends GeneratedBinaryOp[Int,DenseVectorRow[Int],OpDiv,DenseVectorRow[Int]](OpDiv)\n  implicit object OpAddIntDenseVectorRowLong extends GeneratedBinaryOp[Int,DenseVectorRow[Long],OpAdd,DenseVectorRow[Long]](OpAdd)\n  implicit object OpSubIntDenseVectorRowLong extends GeneratedBinaryOp[Int,DenseVectorRow[Long],OpSub,DenseVectorRow[Long]](OpSub)\n  implicit object OpMulIntDenseVectorRowLong extends GeneratedBinaryOp[Int,DenseVectorRow[Long],OpMul,DenseVectorRow[Long]](OpMul)\n  implicit object OpDivIntDenseVectorRowLong extends GeneratedBinaryOp[Int,DenseVectorRow[Long],OpDiv,DenseVectorRow[Long]](OpDiv)\n  implicit object OpAddIntDenseVectorRowFloat extends GeneratedBinaryOp[Int,DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubIntDenseVectorRowFloat extends GeneratedBinaryOp[Int,DenseVectorRow[Float],OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulIntDenseVectorRowFloat extends GeneratedBinaryOp[Int,DenseVectorRow[Float],OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivIntDenseVectorRowFloat extends GeneratedBinaryOp[Int,DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddIntDenseVectorRowDouble extends GeneratedBinaryOp[Int,DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubIntDenseVectorRowDouble extends GeneratedBinaryOp[Int,DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulIntDenseVectorRowDouble extends GeneratedBinaryOp[Int,DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivIntDenseVectorRowDouble extends GeneratedBinaryOp[Int,DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddLongDenseVectorRowInt extends GeneratedBinaryOp[Long,DenseVectorRow[Int],OpAdd,DenseVectorRow[Long]](OpAdd)\n  implicit object OpSubLongDenseVectorRowInt extends GeneratedBinaryOp[Long,DenseVectorRow[Int],OpSub,DenseVectorRow[Long]](OpSub)\n  implicit object OpMulLongDenseVectorRowInt extends GeneratedBinaryOp[Long,DenseVectorRow[Int],OpMul,DenseVectorRow[Long]](OpMul)\n  implicit object OpDivLongDenseVectorRowInt extends GeneratedBinaryOp[Long,DenseVectorRow[Int],OpDiv,DenseVectorRow[Long]](OpDiv)\n  implicit object OpAddLongDenseVectorRowLong extends GeneratedBinaryOp[Long,DenseVectorRow[Long],OpAdd,DenseVectorRow[Long]](OpAdd)\n  implicit object OpSubLongDenseVectorRowLong extends GeneratedBinaryOp[Long,DenseVectorRow[Long],OpSub,DenseVectorRow[Long]](OpSub)\n  implicit object OpMulLongDenseVectorRowLong extends GeneratedBinaryOp[Long,DenseVectorRow[Long],OpMul,DenseVectorRow[Long]](OpMul)\n  implicit object OpDivLongDenseVectorRowLong extends GeneratedBinaryOp[Long,DenseVectorRow[Long],OpDiv,DenseVectorRow[Long]](OpDiv)\n  implicit object OpAddLongDenseVectorRowFloat extends GeneratedBinaryOp[Long,DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubLongDenseVectorRowFloat extends GeneratedBinaryOp[Long,DenseVectorRow[Float],OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulLongDenseVectorRowFloat extends GeneratedBinaryOp[Long,DenseVectorRow[Float],OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivLongDenseVectorRowFloat extends GeneratedBinaryOp[Long,DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddLongDenseVectorRowDouble extends GeneratedBinaryOp[Long,DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubLongDenseVectorRowDouble extends GeneratedBinaryOp[Long,DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulLongDenseVectorRowDouble extends GeneratedBinaryOp[Long,DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivLongDenseVectorRowDouble extends GeneratedBinaryOp[Long,DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddFloatDenseVectorRowInt extends GeneratedBinaryOp[Float,DenseVectorRow[Int],OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubFloatDenseVectorRowInt extends GeneratedBinaryOp[Float,DenseVectorRow[Int],OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulFloatDenseVectorRowInt extends GeneratedBinaryOp[Float,DenseVectorRow[Int],OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivFloatDenseVectorRowInt extends GeneratedBinaryOp[Float,DenseVectorRow[Int],OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddFloatDenseVectorRowLong extends GeneratedBinaryOp[Float,DenseVectorRow[Long],OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubFloatDenseVectorRowLong extends GeneratedBinaryOp[Float,DenseVectorRow[Long],OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulFloatDenseVectorRowLong extends GeneratedBinaryOp[Float,DenseVectorRow[Long],OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivFloatDenseVectorRowLong extends GeneratedBinaryOp[Float,DenseVectorRow[Long],OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddFloatDenseVectorRowFloat extends GeneratedBinaryOp[Float,DenseVectorRow[Float],OpAdd,DenseVectorRow[Float]](OpAdd)\n  implicit object OpSubFloatDenseVectorRowFloat extends GeneratedBinaryOp[Float,DenseVectorRow[Float],OpSub,DenseVectorRow[Float]](OpSub)\n  implicit object OpMulFloatDenseVectorRowFloat extends GeneratedBinaryOp[Float,DenseVectorRow[Float],OpMul,DenseVectorRow[Float]](OpMul)\n  implicit object OpDivFloatDenseVectorRowFloat extends GeneratedBinaryOp[Float,DenseVectorRow[Float],OpDiv,DenseVectorRow[Float]](OpDiv)\n  implicit object OpAddFloatDenseVectorRowDouble extends GeneratedBinaryOp[Float,DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubFloatDenseVectorRowDouble extends GeneratedBinaryOp[Float,DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulFloatDenseVectorRowDouble extends GeneratedBinaryOp[Float,DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivFloatDenseVectorRowDouble extends GeneratedBinaryOp[Float,DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorRowInt extends GeneratedBinaryOp[Double,DenseVectorRow[Int],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorRowInt extends GeneratedBinaryOp[Double,DenseVectorRow[Int],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorRowInt extends GeneratedBinaryOp[Double,DenseVectorRow[Int],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorRowInt extends GeneratedBinaryOp[Double,DenseVectorRow[Int],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorRowLong extends GeneratedBinaryOp[Double,DenseVectorRow[Long],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorRowLong extends GeneratedBinaryOp[Double,DenseVectorRow[Long],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorRowLong extends GeneratedBinaryOp[Double,DenseVectorRow[Long],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorRowLong extends GeneratedBinaryOp[Double,DenseVectorRow[Long],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorRowFloat extends GeneratedBinaryOp[Double,DenseVectorRow[Float],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorRowFloat extends GeneratedBinaryOp[Double,DenseVectorRow[Float],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorRowFloat extends GeneratedBinaryOp[Double,DenseVectorRow[Float],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorRowFloat extends GeneratedBinaryOp[Double,DenseVectorRow[Float],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorRowDouble extends GeneratedBinaryOp[Double,DenseVectorRow[Double],OpAdd,DenseVectorRow[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorRowDouble extends GeneratedBinaryOp[Double,DenseVectorRow[Double],OpSub,DenseVectorRow[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorRowDouble extends GeneratedBinaryOp[Double,DenseVectorRow[Double],OpMul,DenseVectorRow[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorRowDouble extends GeneratedBinaryOp[Double,DenseVectorRow[Double],OpDiv,DenseVectorRow[Double]](OpDiv)\n  implicit object OpAddIntDenseVectorColInt extends GeneratedBinaryOp[Int,DenseVectorCol[Int],OpAdd,DenseVectorCol[Int]](OpAdd)\n  implicit object OpSubIntDenseVectorColInt extends GeneratedBinaryOp[Int,DenseVectorCol[Int],OpSub,DenseVectorCol[Int]](OpSub)\n  implicit object OpMulIntDenseVectorColInt extends GeneratedBinaryOp[Int,DenseVectorCol[Int],OpMul,DenseVectorCol[Int]](OpMul)\n  implicit object OpDivIntDenseVectorColInt extends GeneratedBinaryOp[Int,DenseVectorCol[Int],OpDiv,DenseVectorCol[Int]](OpDiv)\n  implicit object OpAddIntDenseVectorColLong extends GeneratedBinaryOp[Int,DenseVectorCol[Long],OpAdd,DenseVectorCol[Long]](OpAdd)\n  implicit object OpSubIntDenseVectorColLong extends GeneratedBinaryOp[Int,DenseVectorCol[Long],OpSub,DenseVectorCol[Long]](OpSub)\n  implicit object OpMulIntDenseVectorColLong extends GeneratedBinaryOp[Int,DenseVectorCol[Long],OpMul,DenseVectorCol[Long]](OpMul)\n  implicit object OpDivIntDenseVectorColLong extends GeneratedBinaryOp[Int,DenseVectorCol[Long],OpDiv,DenseVectorCol[Long]](OpDiv)\n  implicit object OpAddIntDenseVectorColFloat extends GeneratedBinaryOp[Int,DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubIntDenseVectorColFloat extends GeneratedBinaryOp[Int,DenseVectorCol[Float],OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulIntDenseVectorColFloat extends GeneratedBinaryOp[Int,DenseVectorCol[Float],OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivIntDenseVectorColFloat extends GeneratedBinaryOp[Int,DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddIntDenseVectorColDouble extends GeneratedBinaryOp[Int,DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubIntDenseVectorColDouble extends GeneratedBinaryOp[Int,DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulIntDenseVectorColDouble extends GeneratedBinaryOp[Int,DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivIntDenseVectorColDouble extends GeneratedBinaryOp[Int,DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddLongDenseVectorColInt extends GeneratedBinaryOp[Long,DenseVectorCol[Int],OpAdd,DenseVectorCol[Long]](OpAdd)\n  implicit object OpSubLongDenseVectorColInt extends GeneratedBinaryOp[Long,DenseVectorCol[Int],OpSub,DenseVectorCol[Long]](OpSub)\n  implicit object OpMulLongDenseVectorColInt extends GeneratedBinaryOp[Long,DenseVectorCol[Int],OpMul,DenseVectorCol[Long]](OpMul)\n  implicit object OpDivLongDenseVectorColInt extends GeneratedBinaryOp[Long,DenseVectorCol[Int],OpDiv,DenseVectorCol[Long]](OpDiv)\n  implicit object OpAddLongDenseVectorColLong extends GeneratedBinaryOp[Long,DenseVectorCol[Long],OpAdd,DenseVectorCol[Long]](OpAdd)\n  implicit object OpSubLongDenseVectorColLong extends GeneratedBinaryOp[Long,DenseVectorCol[Long],OpSub,DenseVectorCol[Long]](OpSub)\n  implicit object OpMulLongDenseVectorColLong extends GeneratedBinaryOp[Long,DenseVectorCol[Long],OpMul,DenseVectorCol[Long]](OpMul)\n  implicit object OpDivLongDenseVectorColLong extends GeneratedBinaryOp[Long,DenseVectorCol[Long],OpDiv,DenseVectorCol[Long]](OpDiv)\n  implicit object OpAddLongDenseVectorColFloat extends GeneratedBinaryOp[Long,DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubLongDenseVectorColFloat extends GeneratedBinaryOp[Long,DenseVectorCol[Float],OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulLongDenseVectorColFloat extends GeneratedBinaryOp[Long,DenseVectorCol[Float],OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivLongDenseVectorColFloat extends GeneratedBinaryOp[Long,DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddLongDenseVectorColDouble extends GeneratedBinaryOp[Long,DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubLongDenseVectorColDouble extends GeneratedBinaryOp[Long,DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulLongDenseVectorColDouble extends GeneratedBinaryOp[Long,DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivLongDenseVectorColDouble extends GeneratedBinaryOp[Long,DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddFloatDenseVectorColInt extends GeneratedBinaryOp[Float,DenseVectorCol[Int],OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubFloatDenseVectorColInt extends GeneratedBinaryOp[Float,DenseVectorCol[Int],OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulFloatDenseVectorColInt extends GeneratedBinaryOp[Float,DenseVectorCol[Int],OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivFloatDenseVectorColInt extends GeneratedBinaryOp[Float,DenseVectorCol[Int],OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddFloatDenseVectorColLong extends GeneratedBinaryOp[Float,DenseVectorCol[Long],OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubFloatDenseVectorColLong extends GeneratedBinaryOp[Float,DenseVectorCol[Long],OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulFloatDenseVectorColLong extends GeneratedBinaryOp[Float,DenseVectorCol[Long],OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivFloatDenseVectorColLong extends GeneratedBinaryOp[Float,DenseVectorCol[Long],OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddFloatDenseVectorColFloat extends GeneratedBinaryOp[Float,DenseVectorCol[Float],OpAdd,DenseVectorCol[Float]](OpAdd)\n  implicit object OpSubFloatDenseVectorColFloat extends GeneratedBinaryOp[Float,DenseVectorCol[Float],OpSub,DenseVectorCol[Float]](OpSub)\n  implicit object OpMulFloatDenseVectorColFloat extends GeneratedBinaryOp[Float,DenseVectorCol[Float],OpMul,DenseVectorCol[Float]](OpMul)\n  implicit object OpDivFloatDenseVectorColFloat extends GeneratedBinaryOp[Float,DenseVectorCol[Float],OpDiv,DenseVectorCol[Float]](OpDiv)\n  implicit object OpAddFloatDenseVectorColDouble extends GeneratedBinaryOp[Float,DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubFloatDenseVectorColDouble extends GeneratedBinaryOp[Float,DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulFloatDenseVectorColDouble extends GeneratedBinaryOp[Float,DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivFloatDenseVectorColDouble extends GeneratedBinaryOp[Float,DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorColInt extends GeneratedBinaryOp[Double,DenseVectorCol[Int],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorColInt extends GeneratedBinaryOp[Double,DenseVectorCol[Int],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorColInt extends GeneratedBinaryOp[Double,DenseVectorCol[Int],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorColInt extends GeneratedBinaryOp[Double,DenseVectorCol[Int],OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorColLong extends GeneratedBinaryOp[Double,DenseVectorCol[Long],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorColLong extends GeneratedBinaryOp[Double,DenseVectorCol[Long],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorColLong extends GeneratedBinaryOp[Double,DenseVectorCol[Long],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorColLong extends GeneratedBinaryOp[Double,DenseVectorCol[Long],OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorColFloat extends GeneratedBinaryOp[Double,DenseVectorCol[Float],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorColFloat extends GeneratedBinaryOp[Double,DenseVectorCol[Float],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorColFloat extends GeneratedBinaryOp[Double,DenseVectorCol[Float],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorColFloat extends GeneratedBinaryOp[Double,DenseVectorCol[Float],OpDiv,DenseVectorCol[Double]](OpDiv)\n  implicit object OpAddDoubleDenseVectorColDouble extends GeneratedBinaryOp[Double,DenseVectorCol[Double],OpAdd,DenseVectorCol[Double]](OpAdd)\n  implicit object OpSubDoubleDenseVectorColDouble extends GeneratedBinaryOp[Double,DenseVectorCol[Double],OpSub,DenseVectorCol[Double]](OpSub)\n  implicit object OpMulDoubleDenseVectorColDouble extends GeneratedBinaryOp[Double,DenseVectorCol[Double],OpMul,DenseVectorCol[Double]](OpMul)\n  implicit object OpDivDoubleDenseVectorColDouble extends GeneratedBinaryOp[Double,DenseVectorCol[Double],OpDiv,DenseVectorCol[Double]](OpDiv)\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/scalar/Complex.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage scalar;\n\nimport scala.math.{ Fractional, Numeric, Ordering };\nimport scalala.operators._;\n\n/**\n * Immutable complex numbex number representation backed by doubles\n * for the real and imaginary parts.\n *\n * Integration with `scala.math.Numeric` and `scala.math.Fractional` is\n * provided.\n * \n * @author dramage, lancelet\n */\ncase class Complex(real : Double, imag : Double) {\n  override def toString = real + \" + \" + imag + \"i\";\n\n  def +(that : Complex) =\n    Complex(this.real + that.real, this.imag + that.imag);\n\n  def +(that : Int) =\n    Complex(this.real + that, this.imag);\n\n  def +(that : Long) =\n    Complex(this.real + that, this.imag);\n\n  def +(that : Float) =\n    Complex(this.real + that, this.imag);\n\n  def +(that : Double) =\n    Complex(this.real + that, this.imag);\n\n  def -(that : Complex) =\n    Complex(this.real - that.real, this.imag - that.imag);\n\n  def -(that : Int) =\n    Complex(this.real - that, this.imag);\n\n  def -(that : Long) =\n    Complex(this.real - that, this.imag);\n\n  def -(that : Float) =\n    Complex(this.real - that, this.imag);\n\n  def -(that : Double) =\n    Complex(this.real - that, this.imag);\n\n  def *(that : Complex) =\n    Complex(this.real * that.real - this.imag * that.imag,\n            this.real * that.imag + this.imag * that.real);\n\n  def *(that : Int) =\n    Complex(this.real * that, this.imag * that);\n\n  def *(that : Long) =\n    Complex(this.real * that, this.imag * that);\n\n  def *(that : Float) =\n    Complex(this.real * that, this.imag * that);\n\n  def *(that : Double) =\n    Complex(this.real * that, this.imag * that);\n\n  def /(that : Complex) = {\n    val denom = that.real * that.real + that.imag * that.imag;\n    Complex((this.real * that.real + this.imag * that.imag) / denom,\n            (this.imag * that.real - this.real * that.imag) / denom);\n  }\n\n  def /(that : Int) =\n    Complex(this.real / that, this.imag / that);\n\n  def /(that : Long) =\n    Complex(this.real / that, this.imag / that);\n\n  def /(that : Float) =\n    Complex(this.real / that, this.imag / that);\n\n  def /(that : Double) =\n    Complex(this.real / that, this.imag / that);\n\n  def unary_- =\n    Complex(-real, -imag);\n\n  def abs =\n    math.sqrt(real*real + imag*imag);\n\n  def conjugate =\n    Complex(real, -imag);\n\n  override def equals(that : Any) = that match {\n    case that : Complex => this.real == that.real && this.imag == that.imag;\n    case real : Double => this.real == real && this.imag == 0;\n    case real : Int => this.real == real && this.imag == 0;\n    case real : Short => this.real == real && this.imag == 0;\n    case real : Long => this.real == real && this.imag == 0;\n    case real : Float => this.real == real && this.imag == 0;\n    case _ => false;\n  }\n}\n\nobject Complex { outer =>\n\n  /** Constant Complex(0,0). */\n  val zero = new Complex(0,0);\n\n  /** Constant Complex(1,0). */\n  val one = new Complex(1,0);\n\n  /** Constant Complex(NaN, NaN). */\n  val nan = new Complex(Double.NaN, Double.NaN);\n\n  /** Constant Complex(0,1). */\n  val i = new Complex(0,1);\n\n  //\n  // scalar\n  //\n\n  implicit object scalar extends Scalar[Complex] {\n    def zero = outer.zero;\n\n    def one = outer.one;\n\n    def nan = outer.nan;\n\n    def ==(a : Complex, b : Complex) = a == b;\n\n    def !=(a : Complex, b : Complex) = a != b;\n\n    def >(a : Complex, b : Complex) =\n      (a.real > b.real || (a.real == b.real && a.imag > b.imag));\n    \n    def >=(a : Complex, b : Complex) =\n      (a.real >= b.real || (a.real == b.real && a.imag >= b.imag));\n\n    def <(a : Complex, b : Complex) =\n      (a.real < b.real || (a.real == b.real && a.imag < b.imag));\n\n    def <=(a : Complex, b : Complex) =\n      (a.real <= b.real || (a.real == b.real && a.imag <= b.imag));\n\n    def +(a : Complex, b : Complex) = a + b;\n\n    def -(a : Complex, b : Complex) = a - b;\n\n    def *(a : Complex, b : Complex) = a * b;\n    \n    def /(a : Complex, b : Complex) = a / b;\n\n    def norm(a : Complex) = a.abs;\n\n    def toDouble(a : Complex) =\n      throw new UnsupportedOperationException(\"Cannot automatically convert complex numbers to doubles\");\n    \n    def isNaN(a : Complex) =\n      a.real.isNaN || a.imag.isNaN;\n    \n    val manifest = implicitly[ClassManifest[Complex]];\n    \n    val defaultArrayValue =\n      implicitly[scalala.collection.sparse.DefaultArrayValue[Complex]];\n  }\n\n  implicit object decimal extends ScalarDecimal[Complex,Complex] {\n    def decimal = scalar;\n  }\n\n  //\n  // neg\n  //\n\n  implicit object Neg extends UnaryOp[Complex,OpNeg,Complex]\n    { def opType = OpNeg; def apply(v : Complex) = -v; }\n\n  //\n  // cast\n  //\n  \n  implicit object CastIC extends CanCast[Int,Complex]\n    { def apply(v : Int) = Complex(v,0); }\n\n  implicit object CastLC extends CanCast[Long,Complex]\n    { def apply(v : Long) = Complex(v,0); }\n\n  implicit object CastFC extends CanCast[Float,Complex]\n    { def apply(v : Float) = Complex(v,0); }\n\n  implicit object CastDC extends CanCast[Double,Complex]\n    { def apply(v : Double) = Complex(v,0); }\n\n  //\n  // add\n  //\n\n  implicit object AddCC extends BinaryOp[Complex,Complex,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Complex, b : Complex) = a + b; }\n\n  implicit object AddIC extends BinaryOp[Int,Complex,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Int, b : Complex) = a + b; }\n\n  implicit object AddLC extends BinaryOp[Long,Complex,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Long, b : Complex) = a + b; }\n\n  implicit object AddFC extends BinaryOp[Float,Complex,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Float, b : Complex) = a + b; }\n\n  implicit object AddDC extends BinaryOp[Double,Complex,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Double, b : Complex) = a + b; }\n\n  implicit object AddCI extends BinaryOp[Complex,Int,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Complex, b : Int) = a + b; }\n\n  implicit object AddCL extends BinaryOp[Complex,Long,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Complex, b : Long) = a + b; }\n\n  implicit object AddCF extends BinaryOp[Complex,Float,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Complex, b : Float) = a + b; }\n\n  implicit object AddCD extends BinaryOp[Complex,Double,OpAdd,Complex]\n  { def opType = OpAdd; def apply(a : Complex, b : Double) = a + b; }\n\n  //\n  // sub\n  //\n\n  implicit object SubCC extends BinaryOp[Complex,Complex,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Complex, b : Complex) = a - b; }\n\n  implicit object SubIC extends BinaryOp[Int,Complex,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Int, b : Complex) = a - b; }\n\n  implicit object SubLC extends BinaryOp[Long,Complex,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Long, b : Complex) = a - b; }\n\n  implicit object SubFC extends BinaryOp[Float,Complex,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Float, b : Complex) = a - b; }\n\n  implicit object SubDC extends BinaryOp[Double,Complex,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Double, b : Complex) = a - b; }\n\n  implicit object SubCI extends BinaryOp[Complex,Int,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Complex, b : Int) = a - b; }\n\n  implicit object SubCL extends BinaryOp[Complex,Long,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Complex, b : Long) = a - b; }\n\n  implicit object SubCF extends BinaryOp[Complex,Float,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Complex, b : Float) = a - b; }\n\n  implicit object SubCD extends BinaryOp[Complex,Double,OpSub,Complex]\n  { def opType = OpSub; def apply(a : Complex, b : Double) = a - b; }\n\n  //\n  // mul\n  //\n\n  implicit object MulCC extends BinaryOp[Complex,Complex,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Complex, b : Complex) = a * b; }\n\n  implicit object MulIC extends BinaryOp[Int,Complex,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Int, b : Complex) = a * b; }\n\n  implicit object MulLC extends BinaryOp[Long,Complex,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Long, b : Complex) = a * b; }\n\n  implicit object MulFC extends BinaryOp[Float,Complex,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Float, b : Complex) = a * b; }\n\n  implicit object MulDC extends BinaryOp[Double,Complex,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Double, b : Complex) = a * b; }\n\n  implicit object MulCI extends BinaryOp[Complex,Int,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Complex, b : Int) = a * b; }\n\n  implicit object MulCL extends BinaryOp[Complex,Long,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Complex, b : Long) = a * b; }\n\n  implicit object MulCF extends BinaryOp[Complex,Float,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Complex, b : Float) = a * b; }\n\n  implicit object MulCD extends BinaryOp[Complex,Double,OpMul,Complex]\n  { def opType = OpMul; def apply(a : Complex, b : Double) = a * b; }\n\n  //\n  // div\n  //\n\n  implicit object DivCC extends BinaryOp[Complex,Complex,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Complex, b : Complex) = a / b; }\n\n  implicit object DivIC extends BinaryOp[Int,Complex,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Int, b : Complex) = a / b; }\n\n  implicit object DivLC extends BinaryOp[Long,Complex,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Long, b : Complex) = a / b; }\n\n  implicit object DivFC extends BinaryOp[Float,Complex,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Float, b : Complex) = a / b; }\n\n  implicit object DivDC extends BinaryOp[Double,Complex,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Double, b : Complex) = a / b; }\n\n  implicit object DivCI extends BinaryOp[Complex,Int,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Complex, b : Int) = a / b; }\n\n  implicit object DivCL extends BinaryOp[Complex,Long,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Complex, b : Long) = a / b; }\n\n  implicit object DivCF extends BinaryOp[Complex,Float,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Complex, b : Float) = a / b; }\n\n  implicit object DivCD extends BinaryOp[Complex,Double,OpDiv,Complex]\n  { def opType = OpDiv; def apply(a : Complex, b : Double) = a / b; }\n\n  //\n  // scala.math.Numeric and scala.math.Fractional\n  //\n  // TODO: Implement scala.math.Integral trait, if this is ever required\n  //       for some reason.\n\n  /** `Complex` as `scala.math.Numeric` trait.\n    * Conversions to `Int`, `Long`, `Float` and `Double` are only performed\n    * if the imaginary component of the complex number is exactly 0. */\n  trait ComplexIsConflicted extends Numeric[Complex] {\n    def plus(x: Complex, y: Complex): Complex = x + y\n    def minus(x: Complex, y: Complex): Complex = x - y\n    def times(x: Complex, y: Complex): Complex = x * y\n    def negate(x: Complex): Complex = -x\n    def fromInt(x: Int): Complex = Complex(x, 0)\n    def toInt(x: Complex): Int = strictlyReal(x).toInt\n    def toLong(x: Complex): Long = strictlyReal(x).toLong\n    def toFloat(x: Complex): Float = strictlyReal(x).toFloat\n    def toDouble(x: Complex): Double = strictlyReal(x)\n\n    /** Checks that a `Complex` number is strictly real, and returns the real\n      * component. */\n    private def strictlyReal(x: Complex): Double = {\n      require(x.imag == 0.0)  // only proceed if x.imag is *exactly* zero\n      x.real\n    }\n  }\n  /** `Complex` as `scala.math.Fractional` trait. */\n  trait ComplexIsFractional extends ComplexIsConflicted\n\t\t            with Fractional[Complex]\n  {\n    def div(x: Complex, y: Complex): Complex = x / y\n  }\n  /** Ordering for complex numbers: orders lexicographically first\n    * on the real, then on the imaginary part of the number. */ \n  trait ComplexOrdering extends Ordering[Complex] {\n    override def compare(a : Complex, b : Complex) = {\n      if (a.real < b.real) -1\n      else if (a.real > b.real) 1\n      else if (a.imag < b.imag) -1\n      else if (a.imag > b.imag) 1\n      else 0;\n    }\n  }\n  /** Implicit object providing `scala.math.Fractional` capabilities.\n    * Although complex numbers have no natural ordering, some kind of\n    * `Ordering` is required because `Numeric` extends `Ordering`.  Hence,\n    * an ordering based upon the real then imaginary components is used. */\n  implicit object ComplexIsFractional extends ComplexIsFractional\n                                      with ComplexOrdering\n\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/scalar/RichScalar.scala",
    "content": "package scalala.scalar\n\nclass RichScalar(value: Double) {\n  def +(c: Complex): Complex = Complex(value, 0) + c;\n  def -(c: Complex): Complex = Complex(value, 0) - c;\n  def *(c: Complex): Complex = Complex(value, 0) * c;\n  def /(c: Complex): Complex = Complex(value, 0) / c;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/scalar/Scalar.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage scalar;\n\nimport scala.annotation.implicitNotFound;\nimport scalala.collection.sparse.DefaultArrayValue;\n\n/**\n * Marker trait for scalar values.  Scalars must be immutable.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"${V} is not a scalar value\")\ntrait Scalar[@specialized(Int,Short,Long,Float,Double) V] extends Serializable {\n  def zero : V;\n\n  def one : V;\n\n  def nan : V;\n\n  def ==(a : V, b : V) : Boolean;\n\n  def !=(a : V, b : V) : Boolean;\n\n  def >(a : V, b : V) : Boolean;\n\n  def >=(a : V, b : V) : Boolean;\n\n  def <(a : V, b : V) : Boolean;\n\n  def <=(a : V, b : V) : Boolean;\n\n  def +(a : V, b : V) : V;\n\n  def -(a : V, b : V) : V;\n\n  def *(a : V, b : V) : V;\n\n  def /(a : V, b : V) : V;\n\n  def min(a : V, b : V) : V =\n    if (<=(a,b)) a else b;\n\n  def max(a : V, b : V) : V =\n    if (>=(a,b)) a else b;\n\n  /** Returns true if this is a primitive type. */\n  def isPrimitive : Boolean =\n    ! (manifest <:< implicitly[Manifest[AnyRef]]);\n\n  /** Returns the norm of this value, the absolute value as a Double. */\n  def norm(a : V) : Double;\n\n  /** Returns this value as a Double.  May throw UnsupportedOperationException. */\n  def toDouble(a : V) : Double;\n\n  /** Returns true if this is not a number. */\n  def isNaN(a : V) : Boolean;\n\n  /** Returns the class manifest of the scalar type. */\n  def manifest : ClassManifest[V];\n  \n  /** Returns the DefaultArrayValue for this type.  Always this.zero. */\n  def defaultArrayValue : DefaultArrayValue[V];\n}\n\nobject Scalar {\n  implicit object ScalarI extends Scalar[Int] {\n    def zero = 0;\n    def one = 1;\n    def nan = throw new ArithmeticException(\"Operation resulted in integer-valued NaN\");\n    def ==(a : Int, b : Int) = a == b;\n    def !=(a : Int, b : Int) = a != b;\n    def >(a : Int, b : Int) = a > b;\n    def >=(a : Int, b : Int) = a >= b;\n    def <(a : Int, b : Int) = a < b;\n    def <=(a : Int, b : Int) = a <= b;\n    def +(a : Int, b : Int) = a + b;\n    def -(a : Int, b : Int) = a - b;\n    def *(a : Int, b : Int) = a * b;\n    def /(a : Int, b : Int) = a / b;\n    def norm(a : Int) = if (a < 0) -a else a;\n    def toDouble(a : Int) = a;\n    def isNaN(a : Int) = false;\n    val manifest = implicitly[ClassManifest[Int]];\n    val defaultArrayValue = implicitly[DefaultArrayValue[Int]];\n  }\n\n  implicit object ScalarS extends Scalar[Short] {\n    def zero = 0.asInstanceOf[Short];\n    def one = 1.asInstanceOf[Short];\n    def nan = throw new ArithmeticException(\"Operation resulted in short-valued NaN\");\n    def ==(a : Short, b : Short) = a == b;\n    def !=(a : Short, b : Short) = a != b;\n    def >(a : Short, b : Short) = a > b;\n    def >=(a : Short, b : Short) = a >= b;\n    def <(a : Short, b : Short) = a < b;\n    def <=(a : Short, b : Short) = a <= b;\n    def +(a : Short, b : Short) = (a + b).asInstanceOf[Short];\n    def -(a : Short, b : Short) = (a - b).asInstanceOf[Short];\n    def *(a : Short, b : Short) = (a * b).asInstanceOf[Short];\n    def /(a : Short, b : Short) = (a / b).asInstanceOf[Short];\n    def norm(a : Short) = if (a < 0) -a else a;\n    def toDouble(a : Short) = a;\n    def isNaN(a : Short) = false;\n    val manifest = implicitly[ClassManifest[Short]];\n    val defaultArrayValue = implicitly[DefaultArrayValue[Short]];\n  }\n\n  implicit object ScalarL extends Scalar[Long] {\n    def zero = 0l;\n    def one = 1l;\n    def nan = throw new ArithmeticException(\"Operation resulted in long-valued NaN\");\n    def ==(a : Long, b : Long) = a == b;\n    def !=(a : Long, b : Long) = a != b;\n    def >(a : Long, b : Long) = a > b;\n    def >=(a : Long, b : Long) = a >= b;\n    def <(a : Long, b : Long) = a < b;\n    def <=(a : Long, b : Long) = a <= b;\n    def +(a : Long, b : Long) = a + b;\n    def -(a : Long, b : Long) = a - b;\n    def *(a : Long, b : Long) = a * b;\n    def /(a : Long, b : Long) = a / b;\n    def norm(a : Long) = if (a < 0) -a else a;\n    def toDouble(a : Long) = a;\n    def isNaN(a : Long) = false;\n    val manifest = implicitly[ClassManifest[Long]];\n    val defaultArrayValue = implicitly[DefaultArrayValue[Long]];\n  }\n\n  implicit object scalarF extends Scalar[Float] {\n    def zero = 0.0f;\n    def one = 1.0f;\n    def nan = Float.NaN;\n    def ==(a : Float, b : Float) = a == b;\n    def !=(a : Float, b : Float) = a != b;\n    def >(a : Float, b : Float) = a > b;\n    def >=(a : Float, b : Float) = a >= b;\n    def <(a : Float, b : Float) = a < b;\n    def <=(a : Float, b : Float) = a <= b;\n    def +(a : Float, b : Float) = a + b;\n    def -(a : Float, b : Float) = a - b;\n    def *(a : Float, b : Float) = a * b;\n    def /(a : Float, b : Float) = a / b;\n    def norm(a : Float) = if (a < 0) -a else a;\n    def toDouble(a : Float) = a;\n    def isNaN(a : Float) = java.lang.Float.isNaN(a);\n    val manifest = implicitly[ClassManifest[Float]];\n    val defaultArrayValue = implicitly[DefaultArrayValue[Float]];\n  }\n\n  implicit object scalarD extends Scalar[Double] {\n    def zero = 0.0;\n    def one = 1.0;\n    def nan = Double.NaN;\n    def ==(a : Double, b : Double) = a == b;\n    def !=(a : Double, b : Double) = a != b;\n    def >(a : Double, b : Double) = a > b;\n    def >=(a : Double, b : Double) = a >= b;\n    def <(a : Double, b : Double) = a < b;\n    def <=(a : Double, b : Double) = a <= b;\n    def +(a : Double, b : Double) = a + b;\n    def -(a : Double, b : Double) = a - b;\n    def *(a : Double, b : Double) = a * b;\n    def /(a : Double, b : Double) = a / b;\n    def norm(a : Double) = if (a < 0) -a else a;\n    def toDouble(a : Double) = a;\n    def isNaN(a : Double) = java.lang.Double.isNaN(a);\n    val manifest = implicitly[ClassManifest[Double]];\n    val defaultArrayValue = implicitly[DefaultArrayValue[Double]];\n  }\n\n  implicit object scalarB extends Scalar[Boolean] {\n    def zero = false;\n    def one = true;\n    def nan = throw new ArithmeticException(\"Operation resulted in boolean-valued NaN\");\n    def ==(a : Boolean, b : Boolean) = a == b;\n    def !=(a : Boolean, b : Boolean) = a != b;\n    def >(a : Boolean, b : Boolean) = a > b;\n    def >=(a : Boolean, b : Boolean) = a >= b;\n    def <(a : Boolean, b : Boolean) = a < b;\n    def <=(a : Boolean, b : Boolean) = a <= b;\n    def +(a : Boolean, b : Boolean) = a || b;\n    def -(a : Boolean, b : Boolean) = throw new UnsupportedOperationException();\n    def *(a : Boolean, b : Boolean) = a && b;\n    def /(a : Boolean, b : Boolean) = throw new UnsupportedOperationException();\n    def norm(a : Boolean) = if (a) 1.0 else 0.0;\n    def toDouble(a : Boolean) = if (a) 1.0 else 0.0;\n    def isNaN(a : Boolean) = false;\n    def manifest = implicitly[ClassManifest[Boolean]];\n    val defaultArrayValue = implicitly[DefaultArrayValue[Boolean]];\n  }\n\n  /** The default array value for a scalar is zero. */\n  implicit def defaultArrayValue[V:Scalar] : DefaultArrayValue[V] =\n    implicitly[Scalar[V]].defaultArrayValue;\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/scalar/ScalarDecimal.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage scalar;\n\nimport scala.annotation.implicitNotFound;\nimport scalala.collection.sparse.DefaultArrayValue;\n\n/**\n * Get a decimal value for the given scalar type.\n *\n * @author dramage\n */\n@implicitNotFound(msg=\"No decimal defined for ${SV}\")\ntrait ScalarDecimal[SV,DV] {\n  def decimal : Scalar[DV];\n}\n\nobject ScalarDecimal {\n  class DefaultScalarDecimal[SV:Scalar,DV:Scalar] extends ScalarDecimal[SV,DV] {\n    def decimal = implicitly[Scalar[DV]];\n  }\n\n  implicit object ScalarDecimalBD extends DefaultScalarDecimal[Boolean,Double];\n  implicit object ScalarDecimalID extends DefaultScalarDecimal[Int,Double];\n  implicit object ScalarDecimalSD extends DefaultScalarDecimal[Short,Double];\n  implicit object ScalarDecimalLD extends DefaultScalarDecimal[Long,Double];\n  implicit object ScalarDecimalFD extends DefaultScalarDecimal[Float,Double];\n  implicit object ScalarDecimalDD extends DefaultScalarDecimal[Double,Double];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/scalar/package.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\n\n/**\n * Defines i.\n *\n * @author dramage\n */\npackage object scalar {\n  val i = Complex.i;\n\n  implicit def richInt(value : Int) =\n    new RichScalar(value);\n\n  implicit def richLong(value : Long) =\n    new RichScalar(value);\n\n  implicit def richFloat(value : Float) =\n    new RichScalar(value);\n\n  implicit def richDouble(value : Double) =\n    new RichScalar(value);\n}\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/CRSTensor2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain._;\nimport generic.{TensorBuilder,TensorPairsMonadic};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._\nimport tensor.Counter2.Curried\n\n/**\n * A Tensor2 with an open row key domain that maps to an arbitrary Tensor1 as its rows.\n *\n * CRS = Compress Row Storage\n *\n * @author dlwh\n */\ntrait CRSTensor2Like\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V,\n +M1[VV] <: Curried[scala.collection.Map,K1]#Result[VV],\n +T <: Tensor1[K2,V],\n +This<:CRSTensor2[K1,K2,V,T]]\nextends Tensor2Like[K1,K2,V,SetDomain[K1],SetDomain[K2],Domain2[K1,K2],Domain2[K2,K1],This]\n{ self =>\n\n  protected def k2domain:Domain1[K2];\n\n  override def newBuilder[NK,NV:Scalar](domain : IterableDomain[NK])\n  : TensorBuilder[NK,NV,Tensor[NK,NV]] = domain match {\n    case that : IndexDomain =>\n      super.newBuilder(that)\n    case that : Domain1[_] =>\n      mutable.Counter(that)(implicitly[Scalar[NV]]).asBuilder;\n    case that : Domain2[_,_] =>\n      mutable.Counter2(that)(implicitly[Scalar[NV]]).asBuilder;\n    case _ =>\n      super.newBuilder(domain);\n  }\n\n  def data : M1[_<:T];\n\n\n  def apply(i: K1, j: K2) = data(i)(j);\n\n  override def size = {\n    var s = 0;\n    for (m <- data.valuesIterator) {\n      s += m.size\n    }\n    s;\n  }\n\n  override def domain : Domain2[K1,K2] = {\n    new Domain2[K1,K2] {\n      def _1 = new SetDomain(data.keySet)\n      def _2 = k2domain;\n    }\n  }\n\n\n  override def checkKey(k : K1, k2: K2) = data(k).checkKey(k2);\n\n  // TODO: how to implement this nicely?\n  override def checkDomain(d : scalala.tensor.domain.Domain[(K1,K2)]) = ();\n\n    \n  //\n  // faster implementations\n  //\n\n  override def foreachKey[U](fn : ((K1,K2)) => U) : Unit =\n    for((k1,m) <- data; k2 <- m.keys) fn(k1->k2);\n\n  override def foreachValue[U](fn : V => U) : Unit =\n    valuesIterator.foreach(fn);\n    \n  override def foreachTriple[U](fn : (K1,K2,V) => U) : Unit =\n    triplesIterator.foreach(triple => fn(triple._1,triple._2,triple._3));\n\n  override def keysIterator = for ((k1,m) <- data.iterator; k2 <- m.keysIterator) yield (k1,k2);\n\n  override def valuesIterator = for (m <- data.valuesIterator; v <- m.valuesIterator) yield v\n\n  override def pairsIterator = for ((k1,m) <- data.iterator; (k2,v) <- m.pairsIterator) yield (k1,k2)->v;\n  \n  override def triplesIterator = for ((k1,m) <- data.iterator; (k2,v) <- m.pairsIterator) yield (k1,k2,v);\n}\n/**\n * A Tensor2 with an open row key domain that maps to an arbitrary Tensor1 as its rows.\n *\n * CRS = Compress Row Storage\n *\n * @author dlwh\n */\ntrait CRSTensor2\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V, +T<:Tensor1[K2,V]]\nextends Tensor2[K1,K2,V] with CRSTensor2Like[K1,K2,V,Curried[scala.collection.Map,K1]#Result,T,CRSTensor2[K1,K2,V,T]];\n\nobject CRSTensor2 {\n  /**\n   * Returns a new empty CRSTensor2 using the \"template\" to create rows. The actual rows are zero'd out versions of\n   * the template.\n   */\n  def apply[K1,K2,V,T<:mutable.Tensor1[K2,V]](template: T)(implicit view: CanViewAsTensor1[T,K2,V],\n                                                     zeros: CanCreateZerosLike[T,T],\n                                                     scalar: Scalar[V]) : mutable.CRSTensor2[K1,K2,V,T] =\n    mutable.CRSTensor2[K1,K2,V,T](template);\n    \n  implicit def canSliceRow[K1,K2,V,T<:Tensor1[K2,V]] : CanSliceRow[CRSTensor2[K1,K2,V,T],K1,T]\n  = new CanSliceRow[CRSTensor2[K1,K2,V,T],K1,T] {\n    override def apply(from : CRSTensor2[K1,K2,V,T], row : K1) = from.data(row);\n  }\n\n\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Counter.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain._;\nimport generic.{TensorBuilder,TensorPairsMonadic};\n\nimport scalala.scalar.Scalar\nimport scalala.generic.collection._\n;\n\n\n/**\n * A map-like tensor that acts like a collection of key-value pairs where\n * the set of values may grow arbitrarily.\n *\n * @author dramage\n */\ntrait CounterLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +M<:scala.collection.Map[K,V],\n +This<:Counter[K,V]]\nextends Tensor1Like[K,V,SetDomain[K],This] { self =>\n\n  override def newBuilder[NK,NV:Scalar](domain : IterableDomain[NK])\n  : TensorBuilder[NK,NV,Tensor[NK,NV]] = domain match {\n    case that : IndexDomain =>\n      super.newBuilder(that)\n    case that : Domain1[_] =>\n      mutable.Counter(that)(implicitly[Scalar[NV]]).asBuilder;\n    case _ =>\n      super.newBuilder(domain);\n  }\n\n  def data : M;\n\n  override def domain : SetDomain[K] = new SetDomain(data.keySet);\n  \n  override def size = data.size;\n\n  def isEmpty = data.isEmpty\n\n  def contains(k: K) = data.contains(k);\n\n  override def apply(k : K) = {\n    data.get(k) getOrElse scalar.zero\n  };\n\n  def get(k: K) = data.get(k);\n\n  override def checkKey(k : K) = ();\n  \n  override def checkDomain(d : scalala.tensor.domain.Domain[K]) = ();\n  \n  //\n  // faster implementations\n  //\n  \n  override def foreachPair[U](fn : (K,V) => U) : Unit =\n    data.foreach(fn.tupled);\n  \n  override def foreachKey[U](fn : K => U) : Unit =\n    data.keysIterator.foreach(fn);\n  \n  override def foreachValue[U](fn : V => U) : Unit =\n    data.valuesIterator.foreach(fn);\n    \n  override def keysIterator = data.keysIterator;\n  \n  override def valuesIterator = data.valuesIterator;\n  \n  override def pairsIterator = data.iterator;\n}\n\ntrait Counter\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends Tensor1[K,V] with CounterLike[K,V,scala.collection.Map[K,V],Counter[K,V]];\n\nprivate[scalala]\ntrait CounterRowProxyLike[K,V,+This<:CounterRowProxy[K,V]]\nextends Tensor1ProxyLike[K,V,Domain1[K],Counter[K,V],This]\nwith Tensor1RowLike[K,V,Domain1[K],This];\n\nprivate[scalala]\ntrait CounterRowProxy[K,V]\nextends Tensor1Proxy[K,V,Counter[K,V]] with Tensor1Row[K,V]\nwith CounterRowProxyLike[K,V,CounterRowProxy[K,V]];\n\nprivate[scalala]\ntrait CounterColProxyLike[K,V,+This<:CounterColProxy[K,V]]\nextends Tensor1ProxyLike[K,V,Domain1[K],Counter[K,V],This]\nwith Tensor1ColLike[K,V,Domain1[K],This];\n\nprivate[scalala]\ntrait CounterColProxy[K,V]\nextends Tensor1Proxy[K,V,Counter[K,V]] with Tensor1Col[K,V]\nwith CounterColProxyLike[K,V,CounterColProxy[K,V]];\n\ntrait CounterImplicitsLevel0 {\n  /** View a Counter as a row. */\n  implicit def counterAsRow[K,V](counter : Counter[K,V]) : Tensor1Row[K,V]\n  = new CounterRowProxy[K,V] { override def inner = counter; }\n}\n\ntrait CounterImplicitsLevel1 extends CounterImplicitsLevel0 {\n  /** View a Counter as a column. */\n  implicit def counterAsCol[K,V](counter : Counter[K,V]) : Tensor1Col[K,V]\n  = new CounterColProxy[K,V] { override def inner = counter; }\n}\n\nobject Counter extends CounterImplicitsLevel1 {\n  def apply[K,V:Scalar]() : mutable.Counter[K,V] =\n    mutable.Counter();\n  \n  def apply[K,V:Scalar](values : (K,V)*) : mutable.Counter[K,V] =\n    mutable.Counter(values :_ *);\n  \n  def apply[K,V:Scalar](values : TraversableOnce[(K,V)]) : mutable.Counter[K,V] =\n    mutable.Counter(values);\n    \n  def apply[K,V:Scalar](domain : Domain1[K]) =\n    mutable.Counter(domain);\n  \n  def count[K](items : TraversableOnce[K]) : mutable.Counter[K,Int] =\n    mutable.Counter.count(items);\n\n  def count[K](items: K*): mutable.Counter[K,Int] = count(items);\n\n  implicit def CanMapValuesCounter\n  [@specialized(Int) K, @specialized(Int,Double) V, @specialized(Int,Double) RV:Scalar]: CanMapValues[Counter[K, V], V, RV, Counter[K, RV]]\n  = new CanMapValues[Counter[K,V],V,RV,Counter[K,RV]] {\n    override def map(from : Counter[K,V], fn : (V=>RV)) = {\n      val rv = Counter[K,RV]();\n      for( (k,v) <- from.pairsIterator) {\n        rv(k) = fn(from.data(k));\n      }\n      rv;\n    }\n\n    override def mapNonZero(from : Counter[K,V], fn : (V=>RV)) = {\n      val rv = Counter[K,RV]();\n      for( (k,v) <- from.pairsIteratorNonZero) {\n        rv(k) = fn(from.data(k));\n      }\n      rv;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Counter2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain._;\nimport generic.{TensorBuilder,TensorPairsMonadic};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._\nimport tensor.Counter2.Curried\n;\n\n/**\n * A map-like tensor that acts like a collection of key-value pairs where\n * the set of values may grow arbitrarily.\n *\n * @author dlwh\n */\ntrait Counter2Like\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V,\n +M1[VV] <: Curried[scala.collection.Map,K1]#Result[VV],\n +T <: Counter[K2,V],\n +This<:Counter2[K1,K2,V]]\nextends Tensor2Like[K1,K2,V,SetDomain[K1],SetDomain[K2],Domain2[K1,K2],Domain2[K2,K1],This]\n// TODO: this hsould work instead extends CRSTensor2Like[K1,K2,V,M1,T,This]\n//with TensorPairsMonadic[(K1,K2),V,This]\n{ self =>\n\n  override def newBuilder[NK,NV:Scalar](domain : IterableDomain[NK])\n  : TensorBuilder[NK,NV,Tensor[NK,NV]] = domain match {\n    case that : IndexDomain =>\n      super.newBuilder(that)\n    case that : Domain1[_] =>\n      mutable.Counter(that)(implicitly[Scalar[NV]]).asBuilder;\n    case that : Domain2[_,_] =>\n      mutable.Counter2(that)(implicitly[Scalar[NV]]).asBuilder;\n    case _ =>\n      super.newBuilder(domain);\n  }\n\n  def data : M1[_<:T];\n\n  override def size = {\n    var s = 0;\n    for (m <- data.valuesIterator) {\n      s += m.size\n    }\n    s;\n  }\n\n  override def domain : Domain2[K1,K2] = {\n    new Domain2[K1,K2] {\n      def _1 = new SetDomain(data.keySet)\n      def _2 = new SetDomain(data.values.flatMap(_.domain).toSet);\n    }\n  }\n\n  override def apply(k : K1, k2: K2) = data.get(k).map(t => t(k2)) getOrElse scalar.zero;\n\n  override def checkKey(k : K1, k2: K2) = ();\n  \n  override def checkDomain(d : scalala.tensor.domain.Domain[(K1,K2)]) = ();\n\n  def contains(k: K1) = data.contains(k);\n\n  def contains(k1: K1, k2: K2) = data.contains(k1) && data(k1).contains(k2)\n\n\n  //\n  // faster implementations\n  //\n\n  override def foreachKey[U](fn : ((K1,K2)) => U) : Unit =\n    for((k1,m) <- data; k2 <- m.keys) fn(k1->k2);\n\n  override def foreachValue[U](fn : V => U) : Unit =\n    valuesIterator.foreach(fn);\n\n  override def foreachTriple[U](fn : (K1,K2,V) => U) : Unit =\n    triplesIterator.foreach(triple => fn(triple._1,triple._2,triple._3));\n\n  override def keysIterator = for ((k1,m) <- data.iterator; k2 <- m.keysIterator) yield (k1,k2);\n\n  override def valuesIterator = for (m <- data.valuesIterator; v <- m.valuesIterator) yield v\n\n  override def pairsIterator = for ((k1,m) <- data.iterator; (k2,v) <- m.pairsIterator) yield (k1,k2)->v;\n\n  override def triplesIterator = for ((k1,m) <- data.iterator; (k2,v) <- m.pairsIterator) yield (k1,k2,v);\n}\n\ntrait Counter2\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V]\nextends Tensor2[K1,K2,V] with Counter2Like[K1,K2,V,Curried[scala.collection.Map,K1]#Result,Counter[K2,V],Counter2[K1,K2,V]];\n\nobject Counter2 {\n  def apply[K1,K2,V:Scalar]() : mutable.Counter2[K1,K2,V] =\n    mutable.Counter2();\n    \n  def apply[K1,K2,V:Scalar](values : (K1,K2,V)*) : mutable.Counter2[K1,K2,V] =\n    mutable.Counter2(values :_ *);\n    \n  def apply[K1,K2,V:Scalar](values : TraversableOnce[(K1,K2,V)]) : mutable.Counter2[K1,K2,V] =\n    mutable.Counter2(values);\n\n  def apply[K1,K2,V:Scalar](domain : Domain2[K1,K2]) =\n    mutable.Counter2(domain);\n\n  def count[K1,K2](items : TraversableOnce[(K1,K2)]) : mutable.Counter2[K1,K2,Int] =\n    mutable.Counter2.count(items);\n\n  /**\n   * This is just a curried version of scala.collection.Map.\n   * Used to get around Scala's lack of partially applied types.\n   *\n   * @author dlwh\n   */\n  trait Curried[M[_,_],K] {\n    type Result[V] = M[K,V];\n  }\n\n\n  implicit def canSliceRow[K1,K2,V:Scalar] : CanSliceRow[Counter2[K1,K2,V],K1,Counter[K2,V]]\n  = new CanSliceRow[Counter2[K1,K2,V],K1,Counter[K2,V]] {\n    val vS = implicitly[Scalar[V]];\n    override def apply(from : Counter2[K1,K2,V], row : K1) = from.data(row);\n  }\n\n  implicit def canSliceCol[K1,K2,V:Scalar]: CanSliceCol[Counter2[K1,K2,V],K2,Counter[K1,V]]\n  = new CanSliceCol[Counter2[K1,K2,V],K2,Counter[K1,V]] {\n    val vS = implicitly[Scalar[V]];\n    def apply(from: Counter2[K1, K2, V], col: K2) = new Counter[K1,V] {\n      val scalar = vS;\n      def data = new MapSlice(from.data,col);\n    }\n  }\n\n  import scala.collection.Map\n  private class MapSlice[K1,K2,V](m: Map[K1,Counter[K2,V]],col: K2) extends Map[K1,V] {\n    def get(key: K1) = m.get(key).flatMap(_.get(col))\n\n    def iterator = for( (k,inner) <- m.iterator if inner.contains(col)) yield (k,inner(col))\n\n    def +[B1 >: V](kv: (K1, B1)) = Map(kv) ++ this;\n\n    def -(key: K1) = Map() ++ this - key\n  }\n\n//  implicit def Counter2CanSolveCounter[K1,K2,V]\n//  extends BinaryOp[Counter2[K1,K2,V],Counter[K2,V],OpSolveMatrixBy,Counter[K1,V]] {\n//    override def opType = OpSolveMatrixBy;\n//    override def apply(A : Counter2[K1,K2,V], V : Counter[K2,V]) = {\n//      val \n//    }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/DiagonalMatrix.scala",
    "content": "package scalala\npackage tensor\n\nimport domain.TableDomain\nimport scalar.Scalar\n\n/**\n * A matrix with values only on its diagonal, as defined by the\n * given vector.\n * \n * @author dlwh, dramage\n */\nclass DiagonalMatrix[Vec,V](val diag : Vec)\n(implicit val scalar: Scalar[V], view: Vec<:<Vector[V])\nextends Matrix[V] with MatrixLike[V,DiagonalMatrix[Vec,V]] {\n  override def numCols = diag.size;\n  \n  override def numRows = diag.size;\n  \n  override def nonzeroSize = diag.nonzeroSize;\n  \n  override def apply(i: Int, j: Int): V = {\n    diag.checkKey(i);\n    diag.checkKey(j);\n    if (i == j) diag(i) else scalar.zero\n  }\n  \n  override def foreachNonZeroKey[U](fn : (((Int,Int))=>U)) : Boolean = {\n    diag.foreachNonZeroKey((i : Int) => fn((i,i)));\n    false;\n  }\n    \n  override def foreachNonZeroValue[U](fn : (V=>U)) : Boolean = {\n    diag.foreachNonZeroValue(fn);\n    false;\n  }\n\n  override def foreachNonZeroPair[U](fn : ((Int,Int),V)=>U) : Boolean = {\n    diag.foreachNonZeroPair((i : Int, v : V) => fn((i,i),v));\n    false;\n  }\n  \n  override def foreachNonZeroTriple[U](fn : (Int,Int,V)=>U) : Boolean =\n    diag.foreachNonZeroPair((i : Int, v : V) => fn(i,i,v));\n    \n  override def keysIteratorNonZero =\n    diag.keysIteratorNonZero.map(i => (i,i));\n  \n  override def valuesIteratorNonZero =\n    diag.valuesIteratorNonZero;\n  \n  override def pairsIteratorNonZero =\n    diag.pairsIteratorNonZero.map(tup => ((tup._1,tup._1),tup._2));\n  \n  override def triplesIteratorNonZero =\n    diag.pairsIteratorNonZero.map(tup => (tup._1, tup._1, tup._2));\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/DomainFunction.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain._;\n\n/**\n * A function over a Domain of elements of type A returning values\n * of type B.  This type extends PartialFunction by restricting the\n * domain of possible input functions to an explicitly represented domain.\n *\n * @author dramage\n */\ntrait DomainFunction\n[@specialized(Int,Long,Float,Double) K,\n @specialized(Int,Long,Float,Double,Boolean) +V,\n +D <: Domain[K]]\nextends PartialFunction[K, V] {\n  \n  /** The domain over which this function is defined. */\n  def domain : D;\n\n  /** Returns true if the key is in the function's domain. */\n  override def isDefinedAt(key : K) =\n    domain(key);\n\n  /** @throws DomainException if key is not in the domain. */\n  def checkKey(key : K) : Unit = {\n    if (!isDefinedAt(key))\n      throw new DomainException(\"Key \" + key + \" not in domain\");\n  }\n\n  /** @throws DomainException if domain is not equal to this domain. */\n  def checkDomain(domain : Domain[K]) : Unit = {\n    if (this.domain != domain)\n      throw new DomainException(\"Incompatible domain: \"+domain + \" for \" + this.domain);\n  }\n\n  def apply(key : K) : V;\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/LiteralRow.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\n/**\n * Marker trait for a row literal used in Matrix construction.\n *\n * @author dramage\n */\ntrait LiteralRow[-R, @specialized V] {\n  def foreach[X](row : R, fn : ((Int,V) => X));\n  def length(row : R) : Int;\n}\n\nobject LiteralRow {\n  implicit def array[V] : LiteralRow[Array[V],V] = new LiteralRow[Array[V],V] {\n    def foreach[X](arr : Array[V], fn : ((Int,V) => X)) = {\n      for (i <- 0 until arr.length) {\n        fn(i, arr(i));\n      }\n    }\n\n    def length(arr : Array[V]) = arr.length;\n  }\n\n  implicit def row[V] : LiteralRow[VectorRow[V],V] = new LiteralRow[VectorRow[V],V] {\n    def foreach[X](row : VectorRow[V], fn : ((Int,V) => X)) = {\n      row.foreachNonZeroPair(fn);\n    }\n\n    def length(row : VectorRow[V]) = row.size;\n  }\n\n  implicit def tuple2[V] : LiteralRow[Tuple2[V,V],V] = new LiteralRow[Tuple2[V,V],V] {\n    def foreach[X](tup : Tuple2[V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n    }\n\n    def length(tup : Tuple2[V,V]) = 2;\n  }\n\n\n  implicit def tuple3[V] : LiteralRow[Tuple3[V,V,V],V] = new LiteralRow[Tuple3[V,V,V],V] {\n    def foreach[X](tup : Tuple3[V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n    }\n\n    def length(tup : Tuple3[V,V,V]) = 3;\n  }\n\n\n  implicit def tuple4[V] : LiteralRow[Tuple4[V,V,V,V],V] = new LiteralRow[Tuple4[V,V,V,V],V] {\n    def foreach[X](tup : Tuple4[V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n    }\n\n    def length(tup : Tuple4[V,V,V,V]) = 4;\n  }\n\n\n  implicit def tuple5[V] : LiteralRow[Tuple5[V,V,V,V,V],V] = new LiteralRow[Tuple5[V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple5[V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n    }\n\n    def length(tup : Tuple5[V,V,V,V,V]) = 5;\n  }\n\n\n  implicit def tuple6[V] : LiteralRow[Tuple6[V,V,V,V,V,V],V] = new LiteralRow[Tuple6[V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple6[V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n    }\n\n    def length(tup : Tuple6[V,V,V,V,V,V]) = 6;\n  }\n\n\n  implicit def tuple7[V] : LiteralRow[Tuple7[V,V,V,V,V,V,V],V] = new LiteralRow[Tuple7[V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple7[V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n    }\n\n    def length(tup : Tuple7[V,V,V,V,V,V,V]) = 7;\n  }\n\n\n  implicit def tuple8[V] : LiteralRow[Tuple8[V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple8[V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple8[V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n    }\n\n    def length(tup : Tuple8[V,V,V,V,V,V,V,V]) = 8;\n  }\n\n\n  implicit def tuple9[V] : LiteralRow[Tuple9[V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple9[V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple9[V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n    }\n\n    def length(tup : Tuple9[V,V,V,V,V,V,V,V,V]) = 9;\n  }\n\n\n  implicit def tuple10[V] : LiteralRow[Tuple10[V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple10[V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple10[V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n    }\n\n    def length(tup : Tuple10[V,V,V,V,V,V,V,V,V,V]) = 10;\n  }\n\n\n  implicit def tuple11[V] : LiteralRow[Tuple11[V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple11[V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple11[V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n    }\n\n    def length(tup : Tuple11[V,V,V,V,V,V,V,V,V,V,V]) = 11;\n  }\n\n\n  implicit def tuple12[V] : LiteralRow[Tuple12[V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple12[V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple12[V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n    }\n\n    def length(tup : Tuple12[V,V,V,V,V,V,V,V,V,V,V,V]) = 12;\n  }\n\n\n  implicit def tuple13[V] : LiteralRow[Tuple13[V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple13[V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple13[V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n    }\n\n    def length(tup : Tuple13[V,V,V,V,V,V,V,V,V,V,V,V,V]) = 13;\n  }\n\n\n  implicit def tuple14[V] : LiteralRow[Tuple14[V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple14[V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple14[V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n    }\n\n    def length(tup : Tuple14[V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 14;\n  }\n\n\n  implicit def tuple15[V] : LiteralRow[Tuple15[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple15[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple15[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n    }\n\n    def length(tup : Tuple15[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 15;\n  }\n\n\n  implicit def tuple16[V] : LiteralRow[Tuple16[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple16[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple16[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n    }\n\n    def length(tup : Tuple16[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 16;\n  }\n\n\n  implicit def tuple17[V] : LiteralRow[Tuple17[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple17[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple17[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n      fn(16, tup._17);\n    }\n\n    def length(tup : Tuple17[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 17;\n  }\n\n\n  implicit def tuple18[V] : LiteralRow[Tuple18[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple18[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple18[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n      fn(16, tup._17);\n      fn(17, tup._18);\n    }\n\n    def length(tup : Tuple18[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 18;\n  }\n\n\n  implicit def tuple19[V] : LiteralRow[Tuple19[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple19[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple19[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n      fn(16, tup._17);\n      fn(17, tup._18);\n      fn(18, tup._19);\n    }\n\n    def length(tup : Tuple19[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 19;\n  }\n\n\n  implicit def tuple20[V] : LiteralRow[Tuple20[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple20[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple20[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n      fn(16, tup._17);\n      fn(17, tup._18);\n      fn(18, tup._19);\n      fn(19, tup._20);\n    }\n\n    def length(tup : Tuple20[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 20;\n  }\n\n\n  implicit def tuple21[V] : LiteralRow[Tuple21[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple21[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple21[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n      fn(16, tup._17);\n      fn(17, tup._18);\n      fn(18, tup._19);\n      fn(19, tup._20);\n      fn(20, tup._21);\n    }\n\n    def length(tup : Tuple21[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 21;\n  }\n\n\n  implicit def tuple22[V] : LiteralRow[Tuple22[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] = new LiteralRow[Tuple22[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V],V] {\n    def foreach[X](tup : Tuple22[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V], fn : ((Int,V) => X)) = {\n      fn(0, tup._1);\n      fn(1, tup._2);\n      fn(2, tup._3);\n      fn(3, tup._4);\n      fn(4, tup._5);\n      fn(5, tup._6);\n      fn(6, tup._7);\n      fn(7, tup._8);\n      fn(8, tup._9);\n      fn(9, tup._10);\n      fn(10, tup._11);\n      fn(11, tup._12);\n      fn(12, tup._13);\n      fn(13, tup._14);\n      fn(14, tup._15);\n      fn(15, tup._16);\n      fn(16, tup._17);\n      fn(17, tup._18);\n      fn(18, tup._19);\n      fn(19, tup._20);\n      fn(20, tup._21);\n      fn(21, tup._22);\n    }\n\n    def length(tup : Tuple22[V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V,V]) = 22;\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Matrix.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.{DomainException,IndexDomain,TableDomain}\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\nimport dense.DenseMatrix;\n\n/**\n * Implementation trait for a matrix.\n *\n * @author dramage\n */\ntrait MatrixLike[@specialized(Int,Long,Float,Double) V, +This<:Matrix[V]]\nextends Tensor2Like[Int,Int,V,IndexDomain,IndexDomain,TableDomain,TableDomain,This] {\nself =>\n\n  /** Number of rows in this table. */\n  def numRows : Int;\n\n  /** Number of columsn in this table. */\n  def numCols : Int;\n\n  override def size = numRows * numCols;\n\n  override def domain = TableDomain(numRows, numCols);\n\n  override def checkKey(row : Int, col : Int) {\n    if (row < 0 || row >= numRows || col < 0 || col >= numCols)\n      throw new DomainException(\"Index \"+(row,col)+\" out of range.  Size is \"+numRows+\"x\"+numCols);\n  }\n\n  override def foreachKey[U](fn : ((Int,Int))=>U) =\n    for (i <- 0 until numRows; j <- 0 until numCols) fn((i,j));\n\n  /** Returns true if this matrix has the same number of rows as columns. */\n  def isSquare : Boolean =\n    numRows == numCols;\n  \n  /** Returns true if this matrix is symmetric. */\n  def isSymmetric : Boolean = {\n    if (!isSquare) return false;\n    \n    var i = 0;\n    while (i < numRows) {\n      var j = i + 1;\n      while (j < numCols) {\n        if (this(i,j) != this(j,i)) {\n          return false;\n        }\n        j += 1;\n      }\n      i += 1;\n    }\n    \n    return true;\n  }\n\n  /** Returns the sum of the diagonal elements of this matrix. */\n  def trace(implicit add : BinaryOp[V,V,OpAdd,V]) : V = {\n    var rv = this(0,0);\n    var i = 1;\n    var n = math.min(numRows, numCols);\n    while (i < n) {\n      rv = add(rv, this(i,i));\n      i += 1;\n    }\n    rv;\n  }\n\n  /** Returns a copy of this matrix as a DenseMatrix. */\n  def toDense : DenseMatrix[V] = {\n    val rv = DenseMatrix.zeros(numRows, numCols);\n    rv := repr;\n    rv;\n  }\n\n  def toString(maxLines : Int = ScalalaConsole.terminalHeight - 3,\n               maxWidth : Int = ScalalaConsole.terminalWidth,\n               mkValueString : V=>String = buildMkValueString) : String = {\n    val showRows = if (numRows > maxLines) maxLines - 1 else numRows;\n    def colWidth(col : Int) =\n      (0 until showRows).map(row => mkValueString(this(row,col)).length+2).max;\n\n    val colWidths = new scala.collection.mutable.ArrayBuffer[Int];\n    var col = 0;\n    while (col < numCols && colWidths.sum < maxWidth) {\n      colWidths += colWidth(col);\n      col += 1;\n    }\n    \n    // make space for \"... (K total)\"\n    if (colWidths.size < numCols) {\n      while (colWidths.sum + numCols.toString.length + 12 >= maxWidth) {\n        if (colWidths.isEmpty) {\n          return \"%d x %d matrix\".format(numRows, numCols);\n        }\n        colWidths.remove(colWidths.length - 1);\n      }\n    }\n\n    val newline = System.getProperty(\"line.separator\");\n\n    var rv = new scala.StringBuilder;\n    for (row <- 0 until showRows; col <- 0 until colWidths.length) {\n      val cell = mkValueString(this(row,col));\n      rv.append(cell);\n      rv.append(\" \" * (colWidths(col) - cell.length));\n      if (col == colWidths.length - 1) {\n        if (col < numCols - 1) {\n          rv.append(\"...\");\n          if (row == 0) {\n            rv.append(\" (\");\n            rv.append(numCols);\n            rv.append(\" total)\");\n          }\n        }\n        if (row + 1 < showRows) {\n          rv.append(newline);\n        }\n      }\n    }\n    \n    if (numRows > showRows) {\n      rv.append(newline);\n      rv.append(\"... (\");\n      rv.append(numRows);\n      rv.append(\" total)\");\n    }\n\n    rv.toString;\n  }\n  \n  override def toString : String =\n    toString(maxLines = ScalalaConsole.terminalHeight - 3,\n             maxWidth = ScalalaConsole.terminalWidth,\n             mkValueString = buildMkValueString);\n\n  override protected def canEqual(other : Any) : Boolean = other match {\n    case that : Matrix[_] => true;\n    case _ => false;\n  }\n  \n  override def t : Matrix[V] =\n    new MatrixTranspose.Impl[V,Matrix[V]](repr);\n    \n  //\n  // row and column accessors\n  //\n  \n//  def rows[TT:>This,That](implicit CanSliceRow[TT,K1,That]) : Tensor2RowsMonadic[K2,V,This,That] =\n//    new Tensor2RowsMonadic[K2,V,This,That] { override def repr = self.repr; }\n//  \n//  def cols[TT:>This,That](implicit CanSliceCol[TT,K2,That]) : Tensor2ColsMonadic[K1,V,This,That] =\n//    new Tensor2ColsMonadic[K1,V,This,That] { override def repr = self.repr; }\n}\n\ntrait Matrix[@specialized(Int,Long,Float,Double) V]\nextends Tensor2[Int,Int,V]\nwith MatrixLike[V,Matrix[V]];\n\nobject Matrix {\n  implicit def canSliceRow[V:Scalar] : CanSliceRow[Matrix[V],Int,VectorRow[V]]\n  = new CanSliceRow[Matrix[V],Int,VectorRow[V]] {\n    override def apply(from : Matrix[V], row : Int) =\n      new RowSliceImpl[V,Matrix[V]](from,row);\n  }\n\n  implicit def canSliceCol[V:Scalar] : CanSliceCol[Matrix[V],Int,VectorCol[V]]\n  = new CanSliceCol[Matrix[V],Int,VectorCol[V]] {\n    override def apply(from : Matrix[V], col : Int) =\n      new ColSliceImpl[V,Matrix[V]](from, col);\n  }\n\n  implicit def canSliceMatrix[V:Scalar] : CanSliceMatrix[Matrix[V],Int,Int,Matrix[V]]\n  = new CanSliceMatrix[Matrix[V],Int,Int,Matrix[V]] {\n    override def apply(from : Matrix[V], keys1 : Seq[Int], keys2 : Seq[Int]) =\n      new MatrixSliceImpl[V,Matrix[V]](from, keys1, keys2);\n  }\n\n  trait RowSliceLike[V,+Coll<:Matrix[V],+This<:RowSlice[V,Coll]]\n  extends VectorSliceLike[(Int,Int),TableDomain,V,Coll,This] with VectorRowLike[V,This] {\n    def row : Int;\n    override val domain = underlying.domain._2;\n    override def length = underlying.numCols;\n    override def lookup(key : Int) = (row,key);\n  }\n\n  trait RowSlice[V,+Coll<:Matrix[V]]\n  extends VectorSlice[(Int,Int),V,Coll] with VectorRow[V] with RowSliceLike[V,Coll,RowSlice[V,Coll]];\n\n  class RowSliceImpl[V,+Coll<:Matrix[V]]\n  (override val underlying : Coll, override val row : Int)\n  (implicit override val scalar : Scalar[V])\n  extends RowSlice[V,Coll];\n\n  trait ColSliceLike[V,+Coll<:Matrix[V],+This<:ColSlice[V,Coll]]\n  extends VectorSliceLike[(Int,Int),TableDomain,V,Coll,This] with VectorColLike[V,This] {\n    def col : Int;\n    override def domain = underlying.domain._1;\n    override def length = underlying.numRows;\n    override def lookup(key : Int) = (key,col);\n  }\n\n  trait ColSlice[V,+Coll<:Matrix[V]]\n  extends VectorSlice[(Int,Int),V,Coll] with VectorCol[V] with ColSliceLike[V,Coll,ColSlice[V,Coll]];\n\n  class ColSliceImpl[V,+Coll<:Matrix[V]]\n  (override val underlying : Coll, override val col : Int)\n  (implicit override val scalar : Scalar[V])\n  extends ColSlice[V,Coll];\n\n  trait MatrixSliceLike[@specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll<:Matrix[V], +This<:MatrixSlice[V,Coll]]\n  extends TensorSliceLike[(Int,Int),TableDomain,(Int,Int),TableDomain,V,Coll,This]\n  with MatrixLike[V,This] {\n\n    def lookup1(i : Int) : Int;\n    def lookup2(j : Int) : Int;\n\n    /* final */ override def lookup(tup : (Int,Int)) =\n      (lookup1(tup._1), lookup2(tup._2));\n\n    override def apply(i : Int, j : Int) : V =\n      underlying.apply(lookup1(i), lookup2(j));\n  }\n\n  trait MatrixSlice[@specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll<:Matrix[V]]\n  extends TensorSlice[(Int,Int),(Int,Int),V,Coll]\n  with Matrix[V] with MatrixSliceLike[V,Coll,MatrixSlice[V,Coll]];\n\n  class MatrixSliceImpl[V, +Coll<:Matrix[V]]\n  (override val underlying : Coll, val keys1 : Seq[Int], val keys2 : Seq[Int])\n  (implicit override val scalar : Scalar[V])\n  extends MatrixSlice[V, Coll] {\n    override def numRows = keys1.size;\n    override def numCols = keys2.size;\n    override def lookup1(i : Int) = keys1(i);\n    override def lookup2(j : Int) = keys2(j);\n\n    override val domain = TableDomain(keys1.length, keys2.length);\n  }\n\n  implicit def canMulMatrixByMatrix[\n   @specialized(Int,Double) V1, A, ARow, ADomainRow, InnerDomain, ADomain,\n   @specialized(Int,Double) V2, B, BCol, BDomainCol, BDomain,\n   @specialized(Int,Double) RV, RDomain, That]\n  (implicit\n    viewA : A=>Matrix[V1],\n    sliceA : CanSliceRow[A,Int,ARow],\n    viewB : B=>Matrix[V2],\n    sliceB : CanSliceCol[B,Int,BCol],\n    mul : BinaryOp[ARow,BCol,OpMulRowVectorBy,RV],\n    bf : CanBuildTensorFrom[A,TableDomain,(Int,Int),RV,That],\n    scalar : Scalar[RV])\n  : BinaryOp[A, B, OpMulMatrixBy, That] =\n  new BinaryOp[A, B, OpMulMatrixBy, That] {\n    override def opType = OpMulMatrixBy;\n    override def apply(a : A, b : B) = {\n      val domain = new TableDomain(a.numRows,b.numCols)\n      val builder = bf(a, domain);\n      for (i <- a.domain._1; j <- b.domain._2) {\n        builder(i->j) = mul(sliceA(a,i), sliceB(b,j));\n      }\n      builder.result;\n    }\n  }\n\n//  implicit def canAppendMatrixColumns[V]\n//  : CanAppendColumns[Bound[V],Matrix[V],Matrix[V]]\n//  = new CanAppendColumns[Bound[V],Matrix[V],Matrix[V]] {\n//    override def apply(a : Bound[V], b : Matrix[V]) = {\n//      require(a.numRows == b.numRows, \"Arguments must have same number of rows\");\n//      implicit val sv = a.scalar;\n//      val builder = a.newBuilder[(Int,Int),V](TableDomain(a.numRows, a.numCols+b.numCols));\n//      a.foreachNonZero((i,j,v) => builder((i,j)) = v);\n//      b.foreachNonZero((i,j,v) => builder((i,j+a.numCols)) = v);\n//      builder.result.asInstanceOf[Matrix[V]];\n//    }\n//  }\n//\n//  implicit def canAppendVectorColumn[V]\n//  : CanAppendColumns[Bound[V],VectorCol[V],Matrix[V]]\n//  = new CanAppendColumns[Bound[V],VectorCol[V],Matrix[V]] {\n//    override def apply(a : Bound[V], b : VectorCol[V]) = {\n//      require(a.numRows == b.size, \"Arguments must have same number of rows\");\n//      implicit val sv = a.scalar;\n//      val builder = a.newBuilder[(Int,Int),V](TableDomain(a.numRows, a.numCols+1));\n//      a.foreachNonZero((i,j,v) => builder((i,j)) = v);\n//      b.foreachNonZero((i,v) => builder((i,a.numCols)) = v);\n//      builder.result.asInstanceOf[Matrix[V]];\n//    }\n//  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/MatrixSingularException.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\n/**\n * Thrown when trying to sovle using a singular matrix.\n *\n * @author dramage\n */\nclass MatrixSingularException(msg : String) extends RuntimeException(msg) {\n  def this() = this(null);\n}\n\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/MatrixTranspose.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.{IndexDomain,TableDomain};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * A Transpose of any Matrix type is a Matrix.\n *\n * @author dramage\n */\ntrait MatrixTransposeLike\n[@specialized(Int,Long,Float,Double) V, +Coll <: Matrix[V], +This <: MatrixTranspose[V,Coll]]\nextends Tensor2TransposeLike[Int,Int,V,IndexDomain,IndexDomain,TableDomain,TableDomain,Coll,This]\nwith MatrixLike[V,This] {\n  override def domain = underlying.domain.transpose.asInstanceOf[TableDomain];\n  \n  override def numRows = underlying.numCols;\n  override def numCols = underlying.numRows;\n\n  override def t : Coll =\n    underlying;\n}\n\n/**\n * A Transpose of any Matrix type is a Matrix.\n *\n * @author dramage\n */\ntrait MatrixTranspose[@specialized(Int,Long,Float,Double) B, +Coll <: Matrix[B]]\nextends Tensor2Transpose[Int,Int,B,Coll]\nwith Matrix[B] with MatrixTransposeLike[B, Coll, MatrixTranspose[B, Coll]];\n\nobject MatrixTranspose {\n  class Impl[B, +Coll <: Matrix[B]]\n  (override val underlying : Coll)\n  (implicit override val scalar : Scalar[B])\n  extends MatrixTranspose[B,Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/SelectAll.scala",
    "content": "package scalala.tensor\n\n/**\n * For selecting all elements from a matrix row or column.\n * See :: literal.\n *\n * @author dramage\n */\nsealed trait SelectAll;\n\n/**\n * For selecting all elements from a matrix row or column.\n *\n * @author dramage\n */\nobject :: extends SelectAll;\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain._;\nimport generic._;\n\nimport scalala.operators._;\nimport scalala.scalar.{Scalar,ScalarDecimal};\nimport scalala.generic.collection._;\n\nimport scalala.generic.math.{CanMean,CanVariance,CanSqrt};\n\n/**\n * A Tensor is a map from keys K (with a domain) to numeric scalar values V.\n * More specific operations are available on tensors indexed by a single key\n * (Tensor1, Vector) or pair of keys (Tensor2, Matrix).\n *\n * Note that this trait does not support for comprehensions, although its\n * two sub-traits: TensorSeqLike and TensorMapLike do.  The difference is\n * the way in which the collection is viewed.  TensorSeqLike views the\n * collection as one containing values.  TensorMapLike views the collection\n * as one containing key value pairs.\n *\n * @author dramage\n */\ntrait TensorLike\n[@specialized(Int, Long) K,\n @specialized(Int, Long, Float, Double, Boolean) V,\n +D<:IterableDomain[K],\n +This<:Tensor[K,V]]\nextends DomainFunction[K, V, D]\nwith operators.NumericOps[This] with HasValuesMonadic[This,V] {\nself =>\n\n  type Domain = D;\n\n  protected type Self = This;\n\n  /** Returns a pointer to this cast as an instance of This. */\n  def repr : This = this.asInstanceOf[This];\n\n  /** Provides information about the underlying scalar value type V. */\n  implicit val scalar : Scalar[V];\n\n  /**\n   * Returns a builder for constructing new instances like this one,\n   * on the given domain.\n   */\n  def newBuilder[NK,NV](domain : IterableDomain[NK])(implicit scalar : Scalar[NV])\n  : TensorBuilder[NK,NV,Tensor[NK,NV]] = domain match {\n    case that : IndexDomain =>\n      mutable.Vector[NV](that)(scalar).asBuilder;\n    case that : Domain1[_] =>\n      mutable.Tensor1[NK,NV](that.asInstanceOf[Domain1[NK]])(scalar).asBuilder;\n    case that : TableDomain =>\n      mutable.Matrix[NV](that)(scalar).asBuilder;\n    case that : Domain2[_,_] =>\n      mutable.Tensor2[Any,Any,NV](that.asInstanceOf[Domain2[Any,Any]])(scalar).asBuilder.asInstanceOf[TensorBuilder[NK,NV,Tensor[NK,NV]]];\n      // TODO: add this in when we have a mutable.TensorN\n//    case that : ProductNDomain[_] =>\n//      mutable.TensorN(that)(implicitly[Scalar[NV]]).asBuilder;\n    case _ =>\n      mutable.Tensor[NK,NV](domain).asBuilder;\n  }\n\n  //\n  // Collection contents\n  //\n\n  /** The size of this collection. */\n  def size : Int;\n  \n  /** An upper bound on the number of non zero values in this collection. */\n  def nonzeroSize =\n    size;\n\n  /**\n   * Returns the pairs of (K,V) that make up this tensor for use in\n   * for comprehensions.  The returned object can be viewed as a \n   * Map[K,V].\n   */\n  def pairs : TensorPairsMonadic[K,V,This] =\n    new TensorPairsMonadic[K,V,This] { override def repr = self.repr; }\n\n  /**\n   * Returns the keys that make up this tensor for use in\n   * for comprehensions.  The returned object can be viewed as an\n   * Iterable[K].\n   */\n  def keys : TensorKeysMonadic[K,V,This] =\n    new TensorKeysMonadic[K,V,This] { override def repr = self.repr; }\n\n  /**\n   * Returns the values that make up this tensor for use in\n   * for comprehensions.  The returned object can be viewed as an \n   * Iterable[V].\n   */\n  def values : TensorValuesMonadic[K,V,This] =\n    new TensorValuesMonadic[K,V,This] { override def repr = self.repr; }\n\n  /**\n   * Returns a monadic nonzero elements of this tensor.  Then call one of\n   * .pairs .keys or .values for use in for comprehensions.\n   */\n  def nonzero : TensorNonZeroMonadic[K,V,This] =\n    new TensorNonZeroMonadic[K,V,This] { override def repr = self.repr; }\n\n  /**\n   * Applies the given function to each key and its corresponding value.\n   */\n  def foreachPair[U](fn: (K,V) => U) : Unit =\n    foreachKey[U](k => fn(k,apply(k)));\n\n  /**\n   * Applies the given function to each key and its corresponding value\n   * if the value is non-zero (and possibly also some that are zeros).\n   *\n   * @return true if all elements in the tensor were visited.\n   */\n  def foreachNonZeroPair[U](fn : ((K,V)=>U)) : Boolean = {\n    this.foreachPair[U](fn);\n    true;\n  }\n\n  /** Applies the given function to each key in the tensor. */\n  def foreachKey[U](fn: K => U) : Unit =\n    domain.foreach[U](fn);\n\n  /**\n   * Applies the given function to each key if its corresponding value\n   * is non-zero (and possibly some zero-valued keys as well).\n   *\n   * @return true if all keys in the tensor were visisted.\n   */\n  def foreachNonZeroKey[U](fn : K => U) : Boolean = {\n    this.foreachKey[U](fn);\n    true;\n  }\n\n  /**\n   * Applies the given function to each value in the map (one for\n   * each element of the domain, including zeros).\n   */\n  def foreachValue[U](fn : (V=>U)) =\n    foreachKey[U](k => fn(apply(k)));\n\n  /**\n   * Applies the given function to every non-zero value in the map\n   * (and possibly some zeros, too).\n   *\n   * @return true if all elements in the map were visited.\n   */\n  def foreachNonZeroValue[U](fn : (V=>U)) = {\n    this.foreachValue[U](fn);\n    true;\n  }\n\n  /** Returns true if and only if the given predicate is true for all elements. */\n  def forallPairs(fn : (K,V) => Boolean) : Boolean = {\n    foreachPair((k,v) => if (!fn(k,v)) return false);\n    return true;\n  }\n\n  /** Returns true if and only if the given predicate is true for all elements. */\n  def forallValues(fn : V => Boolean) : Boolean = {\n    foreachValue(v => if (!fn(v)) return false);\n    return true;\n  }\n\n  /** Returns true if and only if the given predicate is true for all non-zero elements. */\n  def forallNonZeroPairs(fn : (K,V) => Boolean) : Boolean = {\n    foreachNonZeroPair((k,v) => if (!fn(k,v)) return false);\n    return true;\n  }\n \n  /** Returns true if and only if the given predicate is true for all non-zero elements. */\n  def forallNonZeroValues(fn : V => Boolean) : Boolean = {\n    foreachNonZeroValue(v => if (!fn(v)) return false);\n    return true;\n  }\n\n  /** Creates a new map containing a transformed copy of this map. */\n  def mapPairs[TT>:This,O,That](f : (K,V) => O)\n  (implicit bf : CanMapKeyValuePairs[TT, K, V, O, That]) : That =\n    bf.map(repr, f);\n\n  /** Maps all non-zero key-value pairs values. */\n  def mapNonZeroPairs[TT>:This,O,That](f : (K,V) => O)\n  (implicit bf : CanMapKeyValuePairs[TT, K, V, O, That]) : That =\n    bf.mapNonZero(repr.asInstanceOf[TT], f);\n\n  /** Creates a new map containing a transformed copy of this map. */\n  def mapValues[TT>:This,O,That](f : V => O)\n  (implicit bf : CanMapValues[TT, V, O, That]) : That =\n    bf.map(repr.asInstanceOf[TT], f);\n\n  /** Maps all non-zero values. */\n  def mapNonZeroValues[TT>:This,O,That](f : V => O)\n  (implicit bf : CanMapValues[TT, V, O, That]) : That =\n    bf.mapNonZero(repr.asInstanceOf[TT], f);\n\n  /** Iterates over the keys in the tensor. */\n  def keysIterator : Iterator[K] =\n    domain.iterator;\n\n  /** Iterates over the (possibly) non-zero keys in the tensor. */\n  def keysIteratorNonZero : Iterator[K] =\n    keysIterator;\n\n  /** Iterates over the values in the tensor. */\n  def valuesIterator : Iterator[V] =\n    keysIterator.map(apply);\n\n  /** Iterates over the (possibly) non-zero values in the tensor. */\n  def valuesIteratorNonZero : Iterator[V] =\n    valuesIterator;\n\n  /** Iterates over all elements in the domain and the corresponding value. */\n  def pairsIterator : Iterator[(K,V)] =\n    keysIterator.map(k => (k,this(k)));\n\n  /** Iterates over the (possibly) non-zero pairs in the tensor. */\n  def pairsIteratorNonZero : Iterator[(K,V)] =\n    pairsIterator;\n\n  /** Returns some key for which the given predicate is true. */\n  def find(p : V => Boolean) : Option[K] = {\n    foreachKey(k => if (p(apply(k))) return Some(k));\n    return None;\n  }\n    \n  /** Returns the keys for which the given predicate is true. */\n  def findAll(p : V => Boolean) : Iterator[K] =\n    keysIterator.filter(this andThen p);\n  \n  /**\n   * Constructs a view of this map on which calls to mapValues are\n   * chained together and lazily evaluated.\n   */\n  def view[That](implicit bf : CanView[This,That]) : That =\n    bf.apply(repr);\n\n\n  /**\n   * Creates a new Tensor over the same domain using the given value\n   * function to create each return value in the map.\n   */\n  def joinAll[TT>:This,V2,RV,That](tensor : Tensor[K,V2])(fn : (K,V,V2) => RV)\n  (implicit jj : CanJoin[TT, Tensor[K,V2], K, V, V2]) : Unit =\n    jj.joinAll[RV](repr.asInstanceOf[TT], tensor, (k,v1,v2) => fn(k,v1,v2));\n\n  /**\n   * Creates a new Tensor over the same domain using the given value\n   * function to create each return value in the map where keys in\n   * both this and m are non-zero.\n   */\n  def joinBothNonZero[TT>:This,V2,RV,That](tensor : Tensor[K,V2])(fn : (K,V,V2) => RV)\n  (implicit jj : CanJoin[TT, Tensor[K,V2], K, V, V2]) : Unit =\n    jj.joinBothNonZero[RV](repr.asInstanceOf[TT], tensor, (k,v1,v2) => fn(k,v1,v2));\n\n  /**\n   * Creates a new Tensor over the same domain using the given value\n   * function to create each return value in the map where keys in\n   * either this or m are non-zero.\n   */\n  def joinEitherNonZero[TT>:This,V2,RV,That](tensor : Tensor[K,V2])(fn : (K,V,V2) => RV)\n  (implicit jj : CanJoin[TT, Tensor[K,V2], K, V, V2]) : Unit =\n    jj.joinEitherNonZero[RV](repr.asInstanceOf[TT], tensor, (k,v1,v2) => fn(k,v1,v2));\n\n  //\n  // Slice construction\n  //\n\n  /** The value at the given key.  Takes precedence over apply(keys : K*). */\n  def apply(key : K) : V;\n\n  /** Creates a view backed by the given keys, returning them as a sequence. */\n  def apply[That](keys : K*)\n  (implicit bf : CanSliceVector[This, K, That]) : That =\n    bf(repr, keys);\n\n  /** Creates a view backed by the \"true\" elements in selected. */\n  def apply[That](selected : Tensor[K,Boolean])\n  (implicit bf : CanSliceVector[This, K, That]) : That =\n    bf(repr, domain.filter(selected).toIndexedSeq);\n\n  /** Creates a view backed by the given keys, returning them as a sequence. */\n  def apply[That](keys : TraversableOnce[K])\n  (implicit bf : CanSliceVector[This, K, That]) : That =\n    bf(repr, keys.toIndexedSeq);\n\n  /** Creates a view for the given elements with new indexes I, backed by this map. */\n  def apply[I,That](keys : (I,K)*)\n  (implicit bf : CanSliceTensor[This, K, I, That]) : That =\n    apply[I,That](keys.toMap[I,K](Predef.conforms[(I, K)]));\n\n  /** Creates a view for the given elements with new indexes I, backed by this map. */\n  def apply[I,That](keys : TraversableOnce[(I,K)])\n  (implicit bf : CanSliceTensor[This, K, I, That]) : That =\n    apply[I,That](keys.toMap[I,K](Predef.conforms[(I, K)]));\n\n  /** Creates a view for the given elements with new indexes I, backed by this map. */\n  def apply[I,That](keys : scala.collection.Map[I,K])\n  (implicit bf : CanSliceTensor[This, K, I, That]) : That =\n    bf(repr, keys);\n\n  //\n  // Sorting\n  //\n\n  /**\n   * Returns the elements of this.domain ordered by their values in this map.\n   * Currently this method is not particularly efficient, as it creates several\n   * in-memory arrays the size of the domain.\n   */\n  def argsort(implicit ord : Ordering[V]) : List[K] =\n    keys.toList.sortWith((i:K, j:K) => ord.lt(this(i), this(j)));\n\n  /**\n   * Returns a sorted view of the current map.  Equivalent to calling\n   * <code>x(x.argsort)</code>.  Changes to the sorted view are\n   * written-through to the underlying map.\n   */\n  def sorted[That](implicit bf : CanSliceVector[This, K, That], ord : Ordering[V]) : That =\n    this.apply[That](this.argsort);\n\n\n  //\n  // Collection level queries\n  //\n\n  /** Returns a key associated with the largest value in the tensor. */\n  def argmax : K = {\n    if (!pairsIterator.hasNext) {\n      throw new UnsupportedOperationException(\"Empty .max\");\n    }\n    var (arg,max) = pairsIterator.next;\n    foreachPair((k,v) => if (scalar.>(v, max)) { max = v; arg = k; });\n    arg;\n  }\n\n  /** Returns a key associated with the smallest value in the tensor. */\n  def argmin : K = {\n    if (!pairsIterator.hasNext) {\n      throw new UnsupportedOperationException(\"Empty .min\");\n    }\n    var (arg,min) = pairsIterator.next;\n    foreachPair((k,v) => if (scalar.<(v,min)) { min = v; arg = k; });\n    arg;\n  }\n\n  /** Returns the max of the values in this tensor. */\n  def max : V = {\n    if (!valuesIterator.hasNext) {\n      throw new UnsupportedOperationException(\"Empty .max\");\n    }\n    var max = valuesIterator.next;\n    if (foreachNonZeroValue(v => { max = scalar.max(max,v) })) {\n      return max;\n    } else {\n      return scalar.max(max, scalar.zero);\n    }\n  }\n\n  /** Returns the min of the values in this tensor. */\n  def min : V = {\n    if (!valuesIterator.hasNext) {\n      throw new UnsupportedOperationException(\"Empty .min\");\n    }\n    var min = valuesIterator.next;\n    if (foreachNonZeroValue(v => { min = scalar.min(min,v); })) {\n      return min;\n    } else {\n      return scalar.min(min, scalar.zero)\n    }\n  }\n\n  /** Returns the sum of the values in this tensor. */\n  def sum : V = {\n    var sum = scalar.zero;\n    foreachNonZeroValue(v => sum = scalar.+(sum,v));\n    return sum;\n  }\n\n  /**\n   * Returns the mean of the values in this tensor.\n   * The returned type is a decimal version of the scalar type of this tensor.\n   */\n  def mean[D](implicit calc : CanMean[This,D]) : D =\n    calc(repr);\n\n  /**\n   * Returns the variance of the values in this tensor.\n   * The returned type is a decimal version of the scalar type of this tensor.\n   */\n  def variance[D](implicit calc : CanVariance[This,D]) : D =\n    calc(repr);\n  \n  /**\n   * Returns the standard deviation of the values in this tensor.\n   * The returned type is a decimal version of the scalar type of this tensor.\n   */\n  def stddev[D](implicit calc : CanVariance[This,D], sqrt : CanSqrt[D,D]) : D =\n    sqrt(calc(repr));\n\n  //\n  // Conversions\n  //\n\n  /** Returns an ordering over the domain based on the values in this map. */\n  def asOrdering(implicit ord : Ordering[V]) : Ordering[K] = new Ordering[K] {\n    override def compare(a : K, b : K) = ord.compare(self(a), self(b));\n  }\n\n  /** Returns an unmodifiable Map-like view of this Tensor. */\n  def asMap : scala.collection.Map[K,V] =\n    pairs;\n\n  /** Creates a new copy of this Tensor as a scala map. */\n  def toMap : Map[K,V] =\n    asMap.toMap;\n\n  protected[this] def buildMkValueString : V=>String = {\n    if (scalar == implicitly[Scalar[Double]])\n      (v : V) => String.format(\"% g\".format(v.asInstanceOf[Double]));\n    else if (scalar == implicitly[Scalar[Float]])\n      (v : V) => String.format(\"% g\".format(v.asInstanceOf[Float]));\n    else\n      (v : V) => v.toString;\n  }\n  \n  protected[this] def buildMkKeyString : K=>String = {\n    (k : K) => k.toString;\n  }\n  \n  /**\n   * Creates a string for the first n non-zero items using the given key string\n   * and value string builder.\n   */\n  def toString(n : Int, mkKeyString : K=>String, mkValueString : V=>String) : String = {\n    val iter = keysIterator;\n    val keys = iter.take(n).toList;\n    \n    if (keys.isEmpty) \n      return \"\";\n    \n    val newline = System.getProperty(\"line.separator\");\n    val keyWidth = keys.iterator.map(mkKeyString).map(_.length).max+1;\n    val rv = (for (key <- nonzero.keys.iterator) yield {\n      val ks = mkKeyString(key);\n      ks + (\" \" * (keyWidth-ks.length)) + mkValueString(apply(key));\n    }).mkString(newline);\n    \n    if (iter.hasNext) {\n      rv + newline + \"... (\"+(domain.size) +\" total)\";\n    } else {\n      rv;\n    }\n  }\n\n  /**\n   * Creates a string representation of the first 10 (potentially) non-zero\n   * items in the tensor.\n   */\n  override def toString : String = {\n    toString(10, buildMkKeyString, buildMkValueString);\n  }\n\n  //\n  // Equality\n  //\n\n  /**\n   * Default implementation iterates the full domain in order, checking\n   * that each function returns the same value.\n   */\n  override def equals(other : Any) : Boolean = other match {\n    case that: Tensor[_,_] =>\n      (this eq that) ||\n      (that canEqual this) &&\n      (this.domain == that.domain) &&\n      ({ val casted = that.asInstanceOf[Tensor[K,V]];\n         this.joinEitherNonZero(casted) { (k,v1,v2) => if (v1 != v2) return false; }\n         true; });\n    case _ => false;\n  }\n\n  /** From recipe in \"Programming in Scala\" section 28.4. */\n  protected def canEqual(other : Any) : Boolean = other match {\n    case that : Tensor[_,_] => true;\n    case _ => false;\n  }\n\n  override def hashCode() =\n    domain.hashCode + pairsIterator.foldLeft(1)((hash,v) => 41 * hash + v.hashCode);\n}\n\n/**\n * K Tensor is a map from keys K (with a domain) to numeric scalar values V.\n * More specific operations are available on tensors indexed by a single key\n * (Tensor1, Vector) or pair of keys (Tensor2, Matrix).\n *\n * @author dramage\n */\ntrait Tensor\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V]\nextends TensorLike[K, V, IterableDomain[K], Tensor[K, V]];\n\nobject Tensor {\n  /** Constructs a tensor for the given domain. */\n  def apply[K,V:Scalar](domain : IterableDomain[K]) =\n    mutable.Tensor.apply(domain);\n\n  implicit def canView[K, V:Scalar] =\n  new CanView[Tensor[K,V],TensorView.IdentityView[K,V,Tensor[K,V]]] {\n    override def apply(from : Tensor[K,V]) =\n      new TensorView.IdentityViewImpl[K,V,Tensor[K,V]](from);\n  }\n\n  implicit def canSliceTensor[K1, K2, V:Scalar] =\n  new CanSliceTensor[Tensor[K1,V], K1, K2, Tensor[K2,V]] {\n    override def apply(from : Tensor[K1,V], keymap : scala.collection.Map[K2,K1]) =\n      new TensorSlice.FromKeyMap[K1, K2, V, Tensor[K1,V]](from, keymap);\n  }\n\n  implicit def canSliceVectorCol[K, V:Scalar] =\n  new CanSliceVector[Tensor[K,V], K, VectorCol[V]] {\n    override def apply(from : Tensor[K,V], keys : Seq[K]) =\n      new VectorColSlice.FromKeySeq[K,V,Tensor[K,V]](from, keys);\n  }\n\n  implicit def canMapValues[K, V, RV, This, D, That]\n  (implicit view : This=>Tensor[K,V], d : CanGetDomain[This,D],\n   bf : CanBuildTensorFrom[This, D, K, RV, That],\n   s : Scalar[RV])\n  : CanMapValues[This,V,RV,That]\n  = new CanMapValues[This,V,RV,That] {\n    override def map(from : This, fn : (V=>RV)) = {\n      val builder = bf(from, from.domain.asInstanceOf[D]);\n      from.foreachPair((k,v) => builder(k) = fn(v));\n      builder.result;\n    }\n    override def mapNonZero(from : This, fn : (V=>RV)) = {\n      val builder = bf(from, from.domain.asInstanceOf[D]);\n      from.foreachNonZeroPair((k,v) => builder(k) = fn(v));\n      builder.result;\n    }\n  }\n\n  implicit def canMapKeyValuePairs[K, V, RV, This, D, That]\n  (implicit view : This=>Tensor[K,V], d : CanGetDomain[This,D],\n   bf : CanBuildTensorFrom[This, D, K, RV, That],\n   s : Scalar[RV])\n  : CanMapKeyValuePairs[This,K,V,RV,That]\n  = new CanMapKeyValuePairs[This,K,V,RV,That] {\n    override def map(from : This, fn : ((K,V)=>RV)) = {\n      val builder = bf(from, from.domain.asInstanceOf[D]);\n      from.foreachPair((k,v) => builder(k) = fn(k,v));\n      builder.result;\n    }\n    override def mapNonZero(from : This, fn : ((K,V)=>RV)) = {\n      val builder = bf(from, from.domain.asInstanceOf[D]);\n      from.foreachNonZeroPair((k,v) => builder(k) = fn(k,v));\n      builder.result;\n    }\n  }\n\n  implicit def canJoin[K, V1, V2, A, B]\n  (implicit viewA : A=>Tensor[K,V1], viewB : B=>Tensor[K,V2])\n  : CanJoin[A, B, K, V1, V2] =\n  new CanJoin[A, B, K, V1, V2] {\n    override def joinAll[RV](_a : A, _b : B, fn : (K,V1,V2)=>RV) = {\n      val a = viewA(_a);\n      val b = viewB(_b);\n      a.checkDomain(b.domain);\n      val visited = scala.collection.mutable.HashSet[K]()\n      a.foreachPair{(k,aV) =>\n        fn(k,aV,b(k))\n        visited += k\n      };\n      b.foreachPair{ (k,bV) =>\n        if(!visited(k)) {\n          fn(k,a(k),bV)\n        }\n      }\n    }\n\n    override def joinEitherNonZero[RV](_a : A, _b : B, fn : (K,V1,V2)=>RV) = {\n      val a  = viewA(_a);\n      val b  = viewB(_b);\n      val aZ = a.scalar.zero;\n      val bZ = b.scalar.zero;\n      a.checkDomain(b.domain);\n      \n      // keys that are visited and are zero (after function application to\n      // catch mutations)\n      var visitedZeros : scala.collection.mutable.HashSet[K] = null;\n\n      val wholeDomainVisited = a.foreachNonZeroPair((k,aV) => {\n        val bV = b(k);\n        if (aV != aZ || bV != bZ) {\n          fn(k, aV, bV);\n        }\n        \n        // if value in a at k is now zero (possibly after mutation), remember\n        // that we visited it\n        if (a(k) == aZ) {\n          if (visitedZeros == null) {\n            visitedZeros = scala.collection.mutable.HashSet[K]();\n          }\n          visitedZeros += k;\n        }\n      });\n\n      if (!wholeDomainVisited || a.domain != b.domain) {\n        b.foreachNonZeroPair((k,bV) => {\n          val aV = a(k);\n          if (aV == aZ && bV != bZ && (visitedZeros == null || !visitedZeros.contains(k))) {\n            fn(k, aV, bV);\n          }\n        });\n      }\n    }\n\n    override def joinBothNonZero[RV](_a : A, _b : B, fn : (K,V1,V2)=>RV) = {\n      val a = viewA(_a);\n      val b = viewB(_b);\n      a.checkDomain(b.domain);\n      val aZ = a.scalar.zero;\n      val bZ = b.scalar.zero;\n      if (a.nonzeroSize <= b.nonzeroSize) {\n        a.foreachNonZeroPair((k,aV) => {\n          val bV = b(k);\n          if (aV != aZ && bV != bZ) fn(k, aV, bV);\n        });\n      } else {\n        b.foreachNonZeroPair((k,bV) => {\n          val aV = a(k);\n          if (aV != aZ && bV != bZ) fn(k, aV, bV);\n        });\n      }\n    }\n  }\n\n  implicit def opTensorUnary[K,V,RV,Op<:OpType,This,That]\n  (implicit view : This=>Tensor[K,V],\n   op : UnaryOp[V,Op,RV],\n   bf : CanMapValues[This,V,RV,That])\n  : UnaryOp[This,Op,That] = new UnaryOp[This,Op,That] {\n    def opType = op.opType;\n    override def apply(from : This) =\n      bf.map(from, op.apply _);\n  }\n\n  implicit def opTensorTensor[K,D,V1,V2,Op<:OpType,RV,A,B,That]\n  (implicit v1 : A=>Tensor[K,V1], v2 : B=>Tensor[K,V2],\n   df : CanGetDomain[A,D],\n   op : BinaryOp[V1,V2,Op,RV],\n   jj : CanJoin[A,B,K,V1,V2],\n   bf : CanBuildTensorForBinaryOp[A,B,D,K,RV,Op,That])\n  : BinaryOp[A,B,Op,That]\n  = new BinaryOp[A,B,Op,That] {\n    override def opType = op.opType;\n    override def apply(a : A, b : B) = {\n      val builder = bf(a,b,(a.domain union b.domain).asInstanceOf[D]);\n      if (opType == OpMul) {\n        jj.joinBothNonZero(a,b,(k,v1,v2) => builder(k) = op(v1,v2));\n      } else if(opType == OpAdd || opType == OpSub) {\n        jj.joinEitherNonZero(a,b,(k,v1,v2) => builder(k) = op(v1,v2));\n      } else {\n        jj.joinAll(a,b,(k,v1,v2) => builder(k) = op(v1,v2));\n      }\n      builder.result;\n    }\n  }\n\n  implicit def opTensorScalar[K,V1,V2,Op<:OpType,RV,This,That]\n  (implicit view : This=>Tensor[K,V1],\n   op : BinaryOp[V1,V2,Op,RV],\n   bf : CanMapValues[This,V1,RV,That],\n   s : Scalar[V2])\n  : BinaryOp[This,V2,Op,That]\n  = new BinaryOp[This,V2,Op,That] {\n    override def opType = op.opType;\n    override def apply(a : This, b : V2) = {\n      if (opType == OpMul && !s.isNaN(b)) {\n        bf.mapNonZero(a, v => op(v, b));\n      } else {\n        bf.map(a, v => op(v, b));\n      }\n    }\n  }\n\n  implicit def opScalarTensor[K,V1,V2,Op<:OpType,RV,This,That]\n  (implicit view : This=>Tensor[K,V2],\n   op : BinaryOp[V1,V2,Op,RV],\n   bf : CanMapValues[This,V2,RV,That],\n   s : Scalar[V1])\n  : BinaryOp[V1,This,Op,That]\n  = new BinaryOp[V1,This,Op,That] {\n    override def opType = op.opType;\n    override def apply(a : V1, b : This) = {\n      if (opType == OpMul && !s.isNaN(a)) {\n        bf.mapNonZero(b, v => op(a, v));\n      } else {\n        bf.map(b, v => op(a, v));\n      }\n    }\n  }\n  \n  implicit def opTensorInnerProduct[K,V1,V2,A,B,RV]\n  (implicit viewA : A=>Tensor[K,V1], viewB: B=>Tensor[K,V2],\n   mul : BinaryOp[V1,V2,OpMul,RV], add : BinaryOp[RV,RV,OpAdd,RV],\n   compatible : CompatibleShape[A,B], s : Scalar[RV])\n  : BinaryOp[A,B,OpMulInner,RV]\n  = new BinaryOp[A,B,OpMulInner,RV] {\n    override def opType = OpMulInner;\n    override def apply(a: A, b: B) = {\n      a.checkDomain(b.domain);\n      var sum = s.zero;\n      if (a.nonzeroSize <= b.nonzeroSize) {\n        a.foreachNonZeroPair((k,aV) => sum = add(sum, mul(aV, b(k))));\n      } else {\n        b.foreachNonZeroPair((k,bV) => sum = add(sum, mul(a(k), bV)));\n      }\n      sum;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain._;\nimport generic.TensorBuilder;\n\nimport operators.{BinaryOp, OpAdd, OpMul}\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\n\n\n/**\n * Implementation trait for a one-axis tensor supports methods like norm.\n *\n * @author dramage\n */\ntrait Tensor1Like\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], +This<:Tensor1[K,V]]\nextends TensorLike[K,V,D,This] { self =>\n\n  /**\n   * Constructs a new Tensor1 like this one based on accumulating values\n   * from the given initial start value, like a foldLeft that returns all\n   * intermediate results.\n   */\n  def accumulate[Z,TT>:This,That](z : Z)(op : (Z,V) => Z)\n  (implicit zs : Scalar[Z], bf : CanBuildTensorFrom[TT,D,K,Z,That]) = {\n    val builder = bf(repr, domain);\n    var acc = z;\n    this.foreachPair((k,v) => {\n      acc = op(acc,v);\n      builder(k) = acc;\n    });\n    builder.result;\n  }\n\n  /**\n   * Returns the culumulative sum of this Tensor1.  Note that this is only\n   * well defined for domains that have a natural and consistent iteration\n   * order.\n   */\n  def cumsum[TT>:This,That](implicit bf : CanBuildTensorFrom[TT,D,K,V,That], add : BinaryOp[V,V,OpAdd,V]) : That =\n    accumulate(scalar.zero)(add);\n\n  /**\n   * Returns the culumulative sum of this Tensor1.  Note that this is only\n   * well defined for domains that have a natural and consistent iteration\n   * order.\n   */\n  def cumprod[TT>:This,That](implicit bf : CanBuildTensorFrom[TT,D,K,V,That], mul : BinaryOp[V,V,OpMul,V]) : That =\n    accumulate(scalar.one)(mul);\n\n  /** Returns the k-norm of this tensor. */\n  def norm(n : Double) : Double = {\n    if (n == 1) {\n      var sum = 0.0;\n      foreachNonZeroValue(v => sum += scalar.norm(v));\n      return sum;\n    } else if (n == 2) {\n      var sum = 0.0;\n      foreachNonZeroValue(v => { val nn = scalar.norm(v); sum += nn * nn });\n      return math.sqrt(sum);\n    } else if (n == Double.PositiveInfinity) {\n      var max = Double.NegativeInfinity;\n      foreachNonZeroValue(v => { val nn = scalar.norm(v); if (nn > max) max = nn; });\n      return max;\n    } else {\n      var sum = 0.0;\n      foreachNonZeroValue(v => { val nn = scalar.norm(v); sum += math.pow(nn,n); });\n      return math.pow(sum, 1.0 / n);\n    }\n  }\n\n  override protected def canEqual(other : Any) : Boolean = other match {\n    case that : Tensor1[_,_] => true;\n    case _ => false;\n  }\n}\n\n/**\n * One-axis tensor supports methods like norm\n * and inner products (dot) with other one-axis tensors.\n *\n * @author dramage\n */\ntrait Tensor1[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends Tensor[K,V] with Tensor1Like[K,V,Domain1[K],Tensor1[K,V]];\n\nobject Tensor1 {\n  /** Constructs a tensor for the given domain. */\n  def apply[K,V:Scalar](domain : Domain1[K]) : Tensor[K,V] =\n    mutable.Tensor1.apply[K,V](domain);\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Col.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.{IterableDomain,Domain1,IndexDomain,CanGetDomain,CanBuildDomain2};\nimport generic.TensorBuilder;\n\nimport scalala.operators._;\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection.CanBuildTensorFrom;\n\n/**\n * Implementation trait for a one-axis tensor shaped as a column.\n *\n * @author dramage\n */\ntrait Tensor1ColLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], +This<:Tensor1Col[K,V]]\nextends Tensor1Like[K,V,D,This] with operators.ColOps[This] { self =>\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) = domain match {\n    case that : IndexDomain =>\n      mutable.Vector[V2](that).asBuilder;\n    case that : Domain1[_] =>\n      mutable.Tensor1Col[K2,V2](that).asBuilder;\n    case _ =>\n      super.newBuilder[K2,V2](domain);\n  }\n  \n  def t : Tensor1Row[K,V] =\n    new Tensor1Row.View[K,V](repr);\n}\n\n/**\n * One-axis tensor shaped as a column.\n *\n * @author dramage\n */\ntrait Tensor1Col[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends Tensor1[K,V] with Tensor1ColLike[K,V,Domain1[K],Tensor1Col[K,V]];\n\nobject Tensor1Col {\n  class View[K,V](override val inner : Tensor1Row[K,V])\n  extends Tensor1Proxy[K,V,Tensor1Row[K,V]] with Tensor1Col[K,V]\n  with Tensor1Like[K,V,Domain1[K],View[K,V]] {\n    override def repr : View[K,V] = this;\n    override def t : Tensor1Row[K,V] = inner;\n  }\n  \n  implicit def canMulTensor1ColByRow[K1,K2,V1,V2,RV,A,DA,B,DB,DThat,That]\n  (implicit viewA : A=>Tensor1Col[K1,V1], viewB : B=>Tensor1Row[K2,V2],\n   dA : CanGetDomain[A,DA], dB : CanGetDomain[B,DB],\n   dThat : CanBuildDomain2[DA,DB,DThat],\n   mul : BinaryOp[V1,V2,OpMul,RV],\n   bf : CanBuildTensorFrom[A, DThat, (K1,K2), RV, That])\n  : BinaryOp[A,B,OpMulColVectorBy,That]\n  = new BinaryOp[A,B,OpMulColVectorBy,That] {\n    override def opType = OpMulColVectorBy;\n    override def apply(a : A, b : B) = {\n      val builder = bf(a, dThat(a.domain.asInstanceOf[DA], b.domain.asInstanceOf[DB]));\n      a.foreachNonZeroPair((i,va) => b.foreachNonZeroPair((j,vb) => builder((i,j)) = mul(va,vb)));\n      builder.result;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Proxy.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.Domain1;\n\nimport scalala.scalar.Scalar;\nimport scalala.operators._;\n\n/**\n * Implementation trait for proxies to a Tensor1 instance.\n *\n * @author dramage\n */\ntrait Tensor1ProxyLike\n[@specialized(Int,Long)K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], Inner<:Tensor1[K,V], +This<:Tensor1[K,V]]\nextends TensorProxyLike[K,V,D,Inner,This] with Tensor1Like[K,V,D,This] {\n  override def norm(n : Double) =\n    inner.norm(n);\n}\n\n/**\n * Proxy to a Tensor1 instance.\n * \n * @author dramage\n */\ntrait Tensor1Proxy\n[@specialized(Int,Long)K, @specialized(Int,Long,Float,Double) V, Inner<:Tensor1[K,V]]\nextends TensorProxy[K,V,Inner] with Tensor1[K,V] with Tensor1ProxyLike[K,V,Domain1[K],Inner,Tensor1Proxy[K,V,Inner]];\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Row.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.{IterableDomain,Domain1,Domain2,IndexDomain};\nimport generic.{TensorBuilder};\n\nimport scalala.generic.collection.{CanSliceCol,CanBuildTensorFrom,CanSliceVector};\nimport scalala.scalar.Scalar;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a one-axis tensor shaped as a row.\n *\n * @author dramage\n */\ntrait Tensor1RowLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], +This<:Tensor1Row[K,V]]\nextends Tensor1Like[K,V,D,This] with operators.RowOps[This] { self =>\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) = domain match {\n    case that : IndexDomain =>\n      mutable.VectorRow[V2](that).asBuilder;\n    case that : Domain1[_] =>\n      mutable.Tensor1Row[K2,V2](that).asBuilder;\n    case _ =>\n      super.newBuilder[K2,V2](domain);\n  }\n  \n  def t : Tensor1Col[K,V] =\n    new Tensor1Col.View[K,V](repr);\n}\n\n/**\n * One-axis tensor shaped as a row.\n *\n * @author dramage\n */\ntrait Tensor1Row[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends Tensor1[K,V] with Tensor1RowLike[K,V,Domain1[K],Tensor1Row[K,V]];\n\nobject Tensor1Row {\n  class View[K,V](override val inner : Tensor1Col[K,V])\n  extends Tensor1Proxy[K,V,Tensor1Col[K,V]] with Tensor1Row[K,V]\n  with Tensor1Like[K,V,Domain1[K],View[K,V]] {\n    override def repr : View[K,V] = this;\n    override def t : Tensor1Col[K,V] = inner;\n  }\n  \n  implicit def canMulTensor1RowByCol[K,V1,V2,A,B,RV]\n  (implicit viewA : A=>Tensor1Row[K,V1], viewB : B=>Tensor1Col[K,V2],\n   dot : BinaryOp[A,B,OpMulInner,RV], scalar : Scalar[RV])\n  : BinaryOp[A,B,OpMulRowVectorBy,RV]\n  = new BinaryOp[A,B,OpMulRowVectorBy,RV] {\n    override def opType = OpMulRowVectorBy;\n    override def apply(a : A, b : B) = dot(a, b);\n  }\n\n  implicit def canMulTensor1RowByMatrix[K1,K2,V1,V2,Col,RV,ThisA,ThisB,D2<:Domain1[K2],That]\n  (implicit viewA : ThisA => Tensor1Row[K1,V1],\n   viewB : ThisB => Tensor2Like[K1,K2,V2,_,D2,_,_,_],\n   slice : CanSliceCol[ThisB,K2,Col],\n   mul : BinaryOp[ThisA,Col,OpMulRowVectorBy,RV], scalar : Scalar[RV],\n   bf : CanBuildTensorFrom[ThisA,D2,K2,RV,That])\n  : BinaryOp[ThisA,ThisB,OpMulRowVectorBy,That]\n  = new BinaryOp[ThisA,ThisB,OpMulRowVectorBy,That] {\n    override def opType = OpMulRowVectorBy;\n    override def apply(a : ThisA, b : ThisB) = {\n      val domain = b.domain.asInstanceOf[Domain2[_,_]]._2.asInstanceOf[D2];\n      val builder : TensorBuilder[K2,RV,That] = bf(a, domain);\n      for (j <- domain.asInstanceOf[Domain1[K2]]) {\n        builder(j) = mul(a, slice(b, j));\n      }\n      builder.result;\n    }\n  }\n\n  implicit def canSliceVectorRow[K, V:Scalar] =\n  new CanSliceVector[Tensor[K,V], K, VectorRow[V]] {\n    override def apply(from : Tensor[K,V], keys : Seq[K]) =\n      new VectorRowSlice.FromKeySeq[K,V,Tensor[K,V]](from, keys);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Slice.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.{IterableDomain,Domain1};\n\n/**\n * Implementation trait for a Tensor1 view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait Tensor1SliceLike\n[@specialized(Int,Long) K1, +D1<:IterableDomain[K1],\n @specialized(Int,Long) K2, +D2<:Domain1[K2],\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll<:Tensor[K1,V],\n +This<:Tensor1Slice[K1,K2,V,Coll]]\nextends TensorSliceLike[K1, D1, K2, D2, V, Coll, This]\nwith Tensor1Like[K2, V, D2, This];\n\n/**\n * A Tensor1 view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait Tensor1Slice\n[@specialized(Int,Long) K1, @specialized(Int,Long) K2,\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll<:Tensor[K1,V]]\nextends TensorSlice[K1,K2,V,Coll] with Tensor1[K2,V]\nwith Tensor1SliceLike[K1, IterableDomain[K1], K2, Domain1[K2], V, Coll, Tensor1Slice[K1, K2, V, Coll]];\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain._;\n\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\nimport generic.TensorTriplesMonadic;\n\n\n/**\n * Implementation trait for tensors indexed by two keys, such as Matrices.\n *\n * TODO: Make up mind about whether implementing classes should provide\n * which one (or both) of the pairs interface and triples interface.\n *\n * @author dramage\n */\ntrait Tensor2Like\n[@specialized(Int) K1, @specialized(Int) K2,\n @specialized(Int,Long,Float,Double,Boolean) V,\n +D1<:Domain1[K1],\n +D2<:Domain1[K2],\n +D<:Domain2[K1,K2],\n +T<:Domain2[K2,K1],\n +This<:Tensor2[K1,K2,V]]\nextends TensorLike[(K1,K2),V,D,This]\nwith operators.MatrixOps[This] { self =>\n  def checkKey(k1 : K1, k2 : K2) : Unit = {\n    if (!domain._1.contains(k1) || !domain._2.contains(k2)) {\n      throw new DomainException((k1,k2)+\" not in domain\");\n    }\n  }\n\n  /* final */ override def checkKey(pos : (K1,K2)) : Unit =\n    checkKey(pos._1, pos._2);\n\n  /** Gets the value indexed by (i,j). */\n  def apply(i : K1, j : K2) : V;\n\n  /** Fixed alias for apply(i,j). */\n  /* final */ override def apply(pos : (K1,K2)) : V =\n    apply(pos._1, pos._2);\n\n  /** Select all columns within a given row. */\n  def apply[TT>:This,That](i : K1, j : SelectAll)(implicit bf : CanSliceRow[TT,K1,That]) : That =\n    bf.apply(repr, i);\n\n  /** Select all rows within a given column. */\n  def apply[TT>:This,That](i : SelectAll, j : K2)(implicit bf : CanSliceCol[TT,K2,That]) : That =\n    bf.apply(repr, j);\n\n  /** Select a sub-matrix of the requested rows and columns. */\n  def apply[TT>:This,That](i : Seq[K1], j : Seq[K2])(implicit bf : CanSliceMatrix[TT,K1,K2,That]) : That =\n    bf.apply(repr, i, j);\n\n  /** Select all columns for a specified set of rows. */\n  def apply[TT>:This,That](i : Seq[K1], j : SelectAll)(implicit bf : CanSliceMatrix[TT,K1,K2,That]) : That =\n    bf.apply(repr, i, domain._2.toIndexedSeq);\n\n  /** Select all rows for a specified set of columns. */\n  def apply[TT>:This,That](i : SelectAll, j : Seq[K2])(implicit bf : CanSliceMatrix[TT,K1,K2,That]) : That =\n    bf.apply(repr, domain._1.toIndexedSeq, j);\n\n  /** Select specified columns within a row. */\n  def apply[TT>:This,That1,That2](i : K1, j : IndexedSeq[K2])\n  (implicit s1 : CanSliceRow[TT,K1,That1], s2 : CanSliceVector[That1,K2,That2]) : That2 =\n    s2.apply(s1.apply(repr, i), j);\n\n  /** Select specified rows within a column. */\n  def apply[TT>:This,That1,That2](i : IndexedSeq[K1], j : K2)\n  (implicit s1 : CanSliceCol[TT,K2,That1], s2 : CanSliceVector[That1,K1,That2]) : That2 =\n    s2.apply(s1.apply(repr, j), i);\n  \n  /** Transpose of the matrix. */\n  def t : Tensor2[K2,K1,V] =\n    new Tensor2Transpose.Impl[K2,K1,V,This](repr);\n\n  //\n  // triples accessors\n  //\n\n  def triples : TensorTriplesMonadic[K1,K2,V,This] =\n    new TensorTriplesMonadic[K1,K2,V,This] { override def repr = self.repr; }\n\n  def foreachTriple[U](fn : (K1,K2,V)=>U) : Unit =\n    foreachPair((k,v) => fn(k._1, k._2, v));\n\n  def foreachNonZeroTriple[U](fn : (K1,K2,V)=>U) : Boolean =\n    foreachNonZeroPair((k,v) => fn(k._1, k._2, v));\n  \n  def mapTriples[TT>:This,RV,That](fn : (K1,K2,V)=>RV)\n  (implicit bf : CanMapKeyValuePairs[TT, (K1,K2), V, RV, That]) : That =\n    mapPairs[TT,RV,That]((k,v) => fn(k._1,k._2,v))(bf);\n\n  def mapNonZeroTriples[TT>:This,RV,That](fn : (K1,K2,V)=>RV)\n  (implicit bf : CanMapKeyValuePairs[TT, (K1,K2), V, RV, That]) : That =\n    mapNonZeroPairs[TT,RV,That]((k,v) => fn(k._1,k._2,v))(bf);\n\n  def triplesIterator : Iterator[(K1,K2,V)] =\n    pairsIterator.map(pair => (pair._1._1,pair._1._2,pair._2));\n\n  def triplesIteratorNonZero : Iterator[(K1,K2,V)] =\n    pairsIteratorNonZero.map(pair => (pair._1._1,pair._1._2,pair._2));\n\n  //\n  // equality\n  //\n\n  override protected def canEqual(other : Any) : Boolean = other match {\n    case that : Tensor2[_,_,_] => true;\n    case _ => false;\n  }\n}\n\n/**\n * Tensors indexed by two keys, such as matrices.\n *\n * @author dramage\n */\ntrait Tensor2\n[@specialized(Int) K1, @specialized(Int) K2,\n @specialized(Int,Long,Float,Double,Boolean) V]\nextends Tensor[(K1,K2),V]\nwith Tensor2Like[K1,K2,V,Domain1[K1],Domain1[K2],Domain2[K1,K2],Domain2[K2,K1],Tensor2[K1,K2,V]]\n\nobject Tensor2 {\n  /** Constructs a tensor for the given domain. */\n  def apply[K1,K2,V:Scalar](domain : Domain2[K1,K2]) =\n    mutable.Tensor2.apply(domain);\n\n  implicit def canSliceRow[T2<:Tensor2[K1,K2,V],K1,K2,V:Scalar] : CanSliceRow[Tensor2[K1,K2,V],K1,Tensor1Row[K2,V]]\n  = new CanSliceRow[Tensor2[K1,K2,V],K1,Tensor1Row[K2,V]] {\n    override def apply(from : Tensor2[K1,K2,V], row : K1) =\n      new RowSliceImpl[K1,K2,V,Tensor2[K1,K2,V]](from,row);\n  }\n\n  implicit def canSliceCol[K1,K2,V:Scalar] : CanSliceCol[Tensor2[K1,K2,V],K2,Tensor1Col[K1,V]]\n  = new CanSliceCol[Tensor2[K1,K2,V],K2,Tensor1Col[K1,V]] {\n    override def apply(from : Tensor2[K1,K2,V], col : K2) =\n      new ColSliceImpl[K1,K2,V,Tensor2[K1,K2,V]](from, col);\n  }\n\n  implicit def canSliceMatrix[K1,K2,V:Scalar]\n  : CanSliceMatrix[Tensor2[K1,K2,V],K1,K2,Matrix[V]]\n  = new CanSliceMatrix[Tensor2[K1,K2,V],K1,K2,Matrix[V]] {\n    override def apply(from : Tensor2[K1,K2,V], keys1 : Seq[K1], keys2 : Seq[K2]) =\n      new MatrixSliceImpl[K1,K2,V,Tensor2[K1,K2,V]](from, keys1, keys2);\n  }\n\n  implicit def canMulTensor2ByTensor1Col[\n    @specialized(Int) K1, @specialized(Int) K2,\n    @specialized(Int,Double) V1, K, AR, ADomainRow, ADomainCol, ADomain,\n    @specialized(Int,Double) V2, V, BD,\n    @specialized(Int,Double) RV, That]\n  (implicit\n   viewA : K=>Tensor2[K1,K2,V1],\n   sliceA : CanSliceRow[K,K1,AR],\n   domainA : CanGetDomain2[K,ADomainRow,ADomainCol,ADomain],\n   viewB : V=>Tensor1Col[K2,V2],\n   mul : BinaryOp[AR,V,OpMulRowVectorBy,RV],\n   bf : CanBuildTensorFrom[V,ADomainRow,K1,RV,That],\n   scalar : Scalar[RV])\n  : BinaryOp[K, V, OpMulMatrixBy, That] =\n  new BinaryOp[K, V, OpMulMatrixBy, That] {\n    override def opType = OpMulMatrixBy;\n    override def apply(a : K, b : V) = {\n      val builder = bf(b, domainA._1(a));\n      for (i <- a.domain._1) {\n        builder(i) = mul(sliceA(a,i), b);\n      }\n      builder.result;\n    }\n  }\n\n  implicit def canMulMatrixByMatrix[\n   @specialized(Int) K1, @specialized(Int) K2, @specialized(Int) K3,\n   @specialized(Int,Double) V1, A, ARow, ADomainRow, InnerDomain, ADomain,\n   @specialized(Int,Double) V2, B, BCol, BDomainCol, BDomain,\n   @specialized(Int,Double) RV, RDomain, That]\n  (implicit\n    viewA : A=>Tensor2[K1,K2,V1],\n    sliceA : CanSliceRow[A,K1,ARow],\n    domainA : CanGetDomain2[A,ADomainRow,InnerDomain,ADomain],\n    viewB : B=>Tensor2[K2,K3,V2],\n    sliceB : CanSliceCol[B,K3,BCol],\n    domainB : CanGetDomain2[B,InnerDomain,BDomainCol,BDomain],\n    mul : BinaryOp[ARow,BCol,OpMulInner,RV],\n    domainR : CanBuildDomain2[ADomainRow,BDomainCol,RDomain],\n    bf : CanBuildTensorForBinaryOp[A,B,RDomain,(K1,K3),RV,OpMulMatrixBy,That],\n    scalar : Scalar[RV])\n  : BinaryOp[A, B, OpMulMatrixBy, That] =\n  new BinaryOp[A, B, OpMulMatrixBy, That] {\n    override def opType = OpMulMatrixBy;\n    override def apply(a : A, b : B) = {\n      val domain = domainR(domainA._1(a), domainB._2(b));\n      val builder = bf(a, b, domain);\n      for (i <- a.domain._1; j <- b.domain._2) {\n        builder((i,j)) = mul(sliceA(a,i), sliceB(b,j));\n      }\n      builder.result;\n    }\n  }\n\n  trait RowSliceLike[K1,K2,V,+Coll<:Tensor2[K1,K2,V],+This<:RowSlice[K1,K2,V,Coll]]\n  extends Tensor1SliceLike[(K1,K2),IterableDomain[(K1,K2)],K2,Domain1[K2],V,Coll,This] with Tensor1RowLike[K2,V,Domain1[K2],This] {\n    def row : K1;\n    override def domain = underlying.domain._2;\n    override def size = domain.size;\n    override def lookup(key : K2) = (row,key);\n  }\n\n  trait RowSlice[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  extends Tensor1Slice[(K1,K2),K2,V,Coll] with Tensor1Row[K2,V] with RowSliceLike[K1,K2,V,Coll,RowSlice[K1,K2,V,Coll]];\n\n  class RowSliceImpl[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  (override val underlying : Coll, override val row : K1)\n  (implicit override val scalar : Scalar[V])\n  extends RowSlice[K1,K2,V,Coll];\n\n  trait ColSliceLike[K1,K2,V,+Coll<:Tensor2[K1,K2,V],+This<:ColSlice[K1,K2,V,Coll]]\n  extends Tensor1SliceLike[(K1,K2),IterableDomain[(K1,K2)],K1,Domain1[K1],V,Coll,This] with Tensor1ColLike[K1,V,Domain1[K1],This] {\n    def col : K2;\n    override val domain = underlying.domain._1;\n    override def size = domain.size;\n    override def lookup(key : K1) = (key,col);\n  }\n\n  trait ColSlice[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  extends Tensor1Slice[(K1,K2),K1,V,Coll] with Tensor1Col[K1,V] with ColSliceLike[K1,K2,V,Coll,ColSlice[K1,K2,V,Coll]];\n\n  class ColSliceImpl[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  (override val underlying : Coll, override val col : K2)\n  (implicit override val scalar : Scalar[V])\n  extends ColSlice[K1,K2,V,Coll];\n\n  trait MatrixSliceLike\n  [@specialized(Int) K1, @specialized(Int) K2,\n   @specialized(Int,Long,Float,Double,Boolean) V,\n   +D1<:Domain1[K1],\n   +D2<:Domain1[K2],\n   +D<:Domain2[K1,K2],\n   +T<:Domain2[K2,K1],\n   +Coll<:Tensor2[K1,K2,V],\n   +This<:MatrixSlice[K1,K2,V,Coll]]\n  extends TensorSliceLike[(K1,K2),D,(Int,Int),TableDomain,V,Coll,This]\n  with MatrixLike[V,This] {\n\n    def lookup1(i : Int) : K1;\n    def lookup2(j : Int) : K2;\n\n    /* final */ override def lookup(tup : (Int,Int)) =\n      (lookup1(tup._1), lookup2(tup._2));\n\n    override def apply(i : Int, j : Int) : V =\n      underlying.apply(lookup1(i), lookup2(j));\n  }\n\n  trait MatrixSlice\n  [@specialized(Int,Long) K1, @specialized(Int,Long) K2,\n   @specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll<:Tensor2[K1,K2,V]]\n  extends TensorSlice[(K1,K2),(Int,Int),V,Coll]\n  with Matrix[V]\n  with MatrixSliceLike[K1,K2,V,Domain1[K1],Domain1[K2],Domain2[K1,K2],Domain2[K2,K1],Coll,MatrixSlice[K1,K2,V,Coll]];\n\n  class MatrixSliceImpl[K1, K2, V, +Coll<:Tensor2[K1,K2,V]]\n  (override val underlying : Coll, val keys1 : Seq[K1], val keys2 : Seq[K2])\n  (implicit override val scalar : Scalar[V])\n  extends MatrixSlice[K1, K2, V, Coll] {\n    override def numRows = keys1.size;\n    override def numCols = keys2.size;\n  \n    override def lookup1(i : Int) = keys1(i);\n    override def lookup2(j : Int) = keys2(j);\n\n    override val domain = TableDomain(keys1.length, keys2.length);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor2Transpose.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain.{Domain1,Domain2};\n\n/**\n * Implementation trait for a transposed view of an underlying Tensor2.\n *\n * @author dramage\n */\ntrait Tensor2TransposeLike\n[@specialized(Int) K2, @specialized(Int) K1,\n @specialized(Int,Long,Float,Double,Boolean) V,\n +D2<:Domain1[K2],\n +D1<:Domain1[K1],\n +T<:Domain2[K2,K1],\n +D<:Domain2[K1,K2],\n +Coll<:Tensor2[K1,K2,V],\n +This<:Tensor2Transpose[K2,K1,V,Coll]]\nextends TensorSliceLike[(K1,K2),D,(K2,K1),T,V,Coll,This]\nwith Tensor2Like[K2,K1,V,D2,D1,T,D,This] {\nself =>\n\n  override def domain = underlying.domain.transpose.asInstanceOf[T];\n  override def size = underlying.size;\n\n  /* final */ override def lookup(tup : (K2,K1)) = tup.swap;\n\n  override def apply(i : K2, j : K1) = underlying.apply(j, i);\n\n  override def t : Coll =\n    underlying;\n}\n\n/**\n * Transposed view of an underlying Tensor2.\n *\n * @author dramage\n */\ntrait Tensor2Transpose\n[@specialized(Int) K2, @specialized(Int) K1,\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll <: Tensor2[K1,K2,V]]\nextends TensorSlice[(K1,K2),(K2,K1),V,Coll]\nwith Tensor2[K2,K1,V]\nwith Tensor2TransposeLike[K2,K1,V,Domain1[K2],Domain1[K1],Domain2[K2,K1],Domain2[K1,K2],Coll,Tensor2Transpose[K2,K1,V,Coll]];\n\n\nobject Tensor2Transpose {\n  /** Default implementation. */\n  class Impl[K2, K1, V, +Coll <: Tensor2[K1,K2,V]]\n  (override val underlying : Coll)\n  (override implicit val scalar : Scalar[V])\n  extends Tensor2Transpose[K2,K1,V,Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorN.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain.DomainN;\n\n/**\n * Tensors indexed by a sequence of keys.\n *\n * @author dramage\n */\ntrait TensorNLike[@specialized(Int) K, @specialized(Int,Long,Float,Double,Boolean) V, +This<:TensorN[K,V]]\nextends TensorLike[Seq[K],V,DomainN[K],This] {\n  /** Gets the value indexed by (i,j). */\n  /* final */ def apply(k : K*) : V =\n    apply(k : Seq[K]);\n\n\n  override protected def canEqual(other : Any) : Boolean = other match {\n    case that : TensorN[_,_] => true;\n    case _ => false;\n  }\n}\n\ntrait TensorN[@specialized(Int) K, @specialized(Int,Long,Float,Double,Boolean) V]\nextends Tensor[Seq[K],V] with TensorNLike[K,V,TensorN[K,V]]\n\nobject TensorN;\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorProxy.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.IterableDomain;\nimport generic.TensorBuilder;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\n\n/**\n * Proxy for a Tensor instance.\n *\n * @author dramage\n */\ntrait TensorProxyLike\n[@specialized(Int, Long) K,\n @specialized(Int, Long, Float, Double, Boolean) V,\n +D<:IterableDomain[K],\n Inner <: Tensor[K,V],\n +This<:Tensor[K,V]]\nextends TensorLike[K,V,D,This] {\n  def inner : Inner;\n  \n  override def repr = inner.asInstanceOf[This];\n\n  override def domain = inner.domain.asInstanceOf[D];\n  \n  override val scalar = inner.scalar;\n\n  override def size = inner.size;\n  \n  override def nonzeroSize = inner.nonzeroSize;\n\n  override def newBuilder[NK,NV:Scalar](domain : IterableDomain[NK])\n  : TensorBuilder[NK,NV,Tensor[NK,NV]] =\n    inner.newBuilder[NK,NV](domain);\n\n  override def foreachPair[U](fn: (K,V) => U) : Unit =\n    inner.foreachPair(fn);\n\n  override def foreachKey[U](fn : (K=>U)) =\n    inner.foreachKey(fn);\n    \n  override def foreachValue[U](fn : (V=>U)) =\n    inner.foreachValue(fn);\n\n  override def foreachNonZeroPair[U](fn : ((K,V)=>U)) : Boolean =\n    inner.foreachNonZeroPair(fn);\n\n  override def foreachNonZeroValue[U](fn : (V=>U)) =\n    inner.foreachNonZeroValue(fn);\n    \n  override def forallPairs(fn : (K,V) => Boolean) : Boolean =\n    inner.forallPairs(fn);\n\n  override def forallNonZeroPairs(fn : (K,V) => Boolean) : Boolean =\n    inner.forallNonZeroPairs(fn);\n\n  override def forallValues(fn : V => Boolean) : Boolean =\n    inner.forallValues(fn);\n \n  override def forallNonZeroValues(fn : V => Boolean) : Boolean =\n    inner.forallNonZeroValues(fn);\n\n  override def pairsIterator : Iterator[(K,V)] =\n    inner.pairsIterator;\n\n  override def keysIterator : Iterator[K] =\n    inner.keysIterator;\n\n  override def valuesIterator : Iterator[V] =\n    inner.valuesIterator;\n\n  override def pairsIteratorNonZero : Iterator[(K,V)] =\n    inner.pairsIteratorNonZero;\n\n  override def keysIteratorNonZero : Iterator[K] =\n    inner.keysIteratorNonZero;\n\n  override def valuesIteratorNonZero : Iterator[V] =\n    inner.valuesIteratorNonZero;\n\n  override def find(p : V => Boolean) : Option[K] =\n    inner.find(p);\n\n  override def findAll(p : V => Boolean) : Iterator[K] =\n    inner.findAll(p);\n\n  override def apply(key : K) : V =\n    inner(key);\n\n  override def argsort(implicit ord : Ordering[V]) : List[K] =\n    inner.argsort;\n\n  override def argmax : K =\n    inner.argmax;\n\n  override def argmin : K =\n    inner.argmin;\n\n  override def max : V =\n    inner.max;\n\n  override def min : V =\n    inner.min;\n\n  override def sum : V =\n    inner.sum;\n\n  override def asOrdering(implicit ord : Ordering[V]) =\n    inner.asOrdering;\n\n  override def asMap =\n    inner.asMap;\n\n  override def toMap =\n    inner.toMap;\n\n  override def hashCode() =\n    inner.hashCode;\n}\n\n/**\n * Proxy for a generic Tensor.\n *\n * @author dramage\n */\ntrait TensorProxy[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V, Inner <: Tensor[K,V]]\nextends Tensor[K,V] with TensorProxyLike[K,V,IterableDomain[K],Inner,TensorProxy[K,V,Inner]];\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorSlice.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain.{IterableDomain,SetDomain};\n\n/**\n * Implementation trait for slices of an underlying Tensor.  A slice\n * is a pass-through view of a (mapped) subset of the original Tensor's\n * domain.\n *\n * @author dramage\n */\ntrait TensorSliceLike\n[@specialized(Int,Long) K1, +D1<:IterableDomain[K1],\n @specialized(Int,Long) K2, +D2<:IterableDomain[K2],\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll<:Tensor[K1,V],\n +This<:TensorSlice[K1,K2,V,Coll]]\nextends TensorLike[K2,V,D2,This] {\nself =>\n\n  /** The collection underlying this view. */\n  protected def underlying: Coll;\n\n  /** Maps the keys of this domain map to the keys of the underlying maps's. */\n  def lookup(key : K2) : K1;\n\n  override def apply(key : K2) =\n    underlying.apply(lookup(key));\n\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) =\n    underlying.newBuilder[K2,V2](domain);\n}\n\n/**\n * Pass-through view of a (key-mapped) subset of an underlying Tensor.\n *\n * @author dramage\n */\ntrait TensorSlice\n[@specialized(Int,Long) K1, @specialized(Int,Long) K2,\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll <: Tensor[K1, V]]\nextends Tensor[K2,V]\nwith TensorSliceLike[K1, IterableDomain[K1], K2, IterableDomain[K2], V, Coll, TensorSlice[K1, K2, V, Coll]];\n\nobject TensorSlice {\n  class FromKeyMap[K1, K2, V, +Coll<:Tensor[K1, V]]\n  (override val underlying : Coll, keymap : scala.collection.Map[K2,K1])\n  (override implicit val scalar : Scalar[V])\n  extends TensorSlice[K1, K2, V, Coll] {\n    override def lookup(key : K2) = keymap(key);\n    override def domain = new SetDomain(keymap.keySet);\n    override def size = keymap.size;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorView.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.IterableDomain;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for pass-through views of underlying Tensor.\n *\n * @author dramage\n */\ntrait TensorViewLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +D<:IterableDomain[K], +Coll <: Tensor[K,_],\n +This<:TensorView[K,V,Coll]]\nextends TensorLike[K,V,D,This] {\nself =>\n\n  /** The collection underlying this view. */\n  def underlying: Coll;\n\n  /** Maps to underlying.domain */\n  override def domain = underlying.domain.asInstanceOf[D];\n\n  override def size = underlying.size;\n\n  /** Views of views should just return this (cast as This) */\n  def view = repr;\n}\n\n/**\n * Pass-through view of an underlying Tensor.\n *\n * @author dramage\n */\ntrait TensorView\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll <: Tensor[K,_]]\nextends Tensor[K,V]\nwith TensorViewLike[K,V,IterableDomain[K],Coll,TensorView[K,V,Coll]];\n\n\nobject TensorView {\n\n  trait IdentityViewLike\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n   +D<:IterableDomain[K],\n   +Coll <: Tensor[K,V], +This <: IdentityView[K,V,Coll]]\n  extends TensorViewLike[K,V,D,Coll,This] {\n    override def apply(key : K) =\n      underlying.apply(key);\n  }\n\n  trait IdentityView\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll <: Tensor[K,V]]\n  extends TensorView[K,V,Coll]\n  with IdentityViewLike[K,V,IterableDomain[K],Coll,IdentityView[K,V,Coll]];\n\n  /** Returns an unmodified view of the given Tensor. */\n  class IdentityViewImpl[K, V, +Coll <: Tensor[K,V]]\n  (override val underlying : Coll)\n  (implicit override val scalar : Scalar[V])\n  extends IdentityView[K,V,Coll];\n\n  trait TransformViewLike\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n   @specialized(Int,Long,Float,Double,Boolean) O,\n   +D<:IterableDomain[K], +Coll <: Tensor[K,V],\n   +This <: TransformView[K,V,O,Coll]]\n  extends TensorViewLike[K,O,D,Coll,This] {\n    /** Transform a value in the underlying map to a value in the view. */\n    def transform(key : K, value : V) : O;\n\n    override def apply(key : K) =\n      transform(key, underlying.apply(key));\n  }\n\n  trait TransformView\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n   @specialized(Int,Long,Float,Double,Boolean) O, +Coll <: Tensor[K,V]]\n  extends TensorView[K,O,Coll]\n  with TransformViewLike[K,V,O,IterableDomain[K],Coll,TransformView[K,V,O,Coll]]\n\n  /**\n   * Returns an unmodified view of the given Tensor with\n   * values transformed by the given function.\n   */\n  class TransformImpl[K, V, O, +Coll <: Tensor[K,V]]\n  (override val underlying : Coll, fn : ((K,V)=>O))\n  (implicit override val scalar : Scalar[O])\n  extends TransformView[K,V,O,Coll] {\n     override def transform(key : K, value : V) = fn(key, value);\n  }\n\n  implicit def mkTransformCanMapValues[K, V1, V2, V3:Scalar] =\n  new CanMapValues[TransformView[K,V1,V2,Tensor[K,V1]],V2,V3,TransformView[K,V1,V3,Tensor[K,V1]]] {\n    override def map(from : TransformView[K,V1,V2,Tensor[K,V1]], fn : (V2=>V3)) =\n      new TransformImpl[K,V1,V3,Tensor[K,V1]](\n        from.underlying, ((k:K, v:V1) => fn(from.transform(k,v))));\n    override def mapNonZero(from : TransformView[K,V1,V2,Tensor[K,V1]], fn : (V2=>V3)) =\n      map(from, fn);\n  }\n\n  implicit def mkTransformCanMapKeyValuePairs[K, V1, V2, V3:Scalar] =\n  new CanMapKeyValuePairs[TransformView[K,V1,V2,Tensor[K,V1]],K,V2,V3,TransformView[K,V1,V3,Tensor[K,V1]]] {\n    override def map(from : TransformView[K,V1,V2,Tensor[K,V1]], fn : ((K,V2)=>V3)) =\n      new TransformImpl[K,V1,V3,Tensor[K,V1]](\n        from.underlying, ((k:K, v:V1) => fn(k,from.transform(k,v))));\n    override def mapNonZero(from : TransformView[K,V1,V2,Tensor[K,V1]], fn : ((K,V2)=>V3)) =\n      map(from, fn);\n  }\n\n  /** Override canMapValues on TensorView instances to construct a lazy view. */\n  implicit def mkIdentityCanMapValues[K, V1, V2:Scalar] =\n  new CanMapValues[IdentityView[K,V1,Tensor[K,V1]],V1,V2,TransformView[K,V1,V2,Tensor[K,V1]]] {\n    override def map(from : IdentityView[K,V1,Tensor[K,V1]], fn : (V1=>V2)) =\n      new TransformImpl[K,V1,V2,Tensor[K,V1]](from.underlying, ((k:K,v:V1) => fn(v)));\n    override def mapNonZero(from : IdentityView[K,V1,Tensor[K,V1]], fn : (V1=>V2)) =\n      map(from, fn);\n  }\n\n  implicit def mkIdentityCanMapKeyValuePairs[K, V1, V2:Scalar] =\n  new CanMapKeyValuePairs[IdentityView[K,V1,Tensor[K,V1]],K,V1,V2,TransformView[K,V1,V2,Tensor[K,V1]]] {\n    override def map(from : IdentityView[K,V1,Tensor[K,V1]], fn : ((K,V1)=>V2)) =\n      new TransformImpl[K,V1,V2,Tensor[K,V1]](from.underlying, fn);\n    override def mapNonZero(from : IdentityView[K,V1,Tensor[K,V1]], fn : ((K,V1)=>V2)) =\n      map(from, fn);\n  }\n}\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/Vector.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.IndexDomain;\n\nimport scalala.generic.collection._;\n\nimport dense.DenseVector;\n\n/**\n * Vectors are Tensor1s on the non-negative integers.\n *\n * @author dramage\n */\ntrait VectorLike[@specialized(Int,Long,Float,Double) V, +This<:Vector[V]]\nextends Tensor1Like[Int,V,IndexDomain,This] { self =>\n\n  /** Returns the number of elements in the domain of this vector. Same as size. */\n  def length : Int;\n\n  override def size = length;\n\n  override def domain = IndexDomain(length);\n  \n  override def foreachKey[U](fn : (Int => U)) =\n    Range(0,size).foreach(fn);\n\n  //\n  // special case for comprehensions\n  //\n  \n  /** Calls this.foreachValue(fn). */\n  def foreach[U](fn : (V=>U)) =\n    this.foreachValue(fn);\n  \n  /** Calls this.mapValues(fn). */\n  def map[TT>:This,RV,That](fn : V => RV)(implicit bf : CanMapValues[TT, V, RV, That]) : That =\n    this.mapValues[TT,RV,That](fn)(bf);\n\n  def filter[TT>:This,That](f : V => Boolean)(implicit cf : CanBuildTensorFrom[TT,IndexDomain,Int,V,That]) =\n    withFilter(f).strict;\n  \n  def withFilter(f : V => Boolean) =\n    new Vector.Filtered[V,This](repr, f);\n\n  /** Calls this.valuesIterator. */\n  def iterator : Iterator[V] =\n    this.valuesIterator;\n\n  //\n  // Views\n  //\n\n  /** Returns a view of this vector as a row. */\n  def asRow : VectorRow[V] = this match {\n    case r : VectorRow[_] => this.asInstanceOf[VectorRow[V]];\n    case _ => new VectorRow.View(repr);\n  }\n\n  /** Returns a view of this vector as a column. */\n  def asCol : VectorCol[V] = this match {\n    case c : VectorCol[_] => this.asInstanceOf[VectorCol[V]];\n    case _ => new VectorCol.View(repr);\n  }\n\n  /** Returns a copy of this vector as a dense vector, preserving shape. */\n  def toDense : DenseVector[V];\n\n  /** Returns a copy of this vector's data as a list. */\n  def toList =\n    List.tabulate(size)(i => this(i));\n\n  /** Returns a copy of this vector's data as a list. */\n  def toArray(implicit m : ClassManifest[V]) =\n    Array.tabulate(size)(i => this(i));\n}\n\n/**\n * Vectors are Tensor1's on the non-negative integers.\n *\n * @author dramage\n */\ntrait Vector[@specialized(Int,Long,Float,Double) V]\nextends Tensor1[Int,V]\nwith VectorLike[V,Vector[V]];\n\n\nobject Vector {\n  class Filtered[@specialized(Int,Long,Float,Double) V, +This<:Vector[V]]\n  (inner : This, filterFn : V => Boolean) {\n    def size = {\n      var rv = 0;\n      inner.foreach(v => if (filterFn(v)) rv += 1);\n      rv;\n    }\n    \n    def withFilter(fn : V => Boolean) =\n      new Filtered[V,This](inner, v => filterFn(v) && fn(v));\n    \n    def foreach[U](fn : V => U) = {\n      for (v <- inner)\n        if (filterFn(v)) fn(v);\n    }\n    \n    def map[U,That](fn : V => U)\n    (implicit bf : CanBuildTensorFrom[This,IndexDomain,Int,U,That]) = {\n      val builder = bf(inner, IndexDomain(size));\n      var i = 0;\n      for (v <- inner) {\n        if (filterFn(v)) {\n          builder(i) = fn(v);\n          i += 1;\n        }\n      }\n      builder.result;\n    }\n    \n//    def flatMap[U,That](fn : V => Traversable[U])\n//    (implicit bf : CanBuildTensorFrom[This,IndexDomain,Int,U,That]) = {\n//      val builder = bf(inner, IndexDomain(size));\n//      var i = 0;\n//      for (v <- inner) {\n//        if (filterFn(v)) {\n//          for (u <- fn(v)) {\n//            builder(i) = u;\n//            i += 1;\n//          }\n//        }\n//      }\n//      builder.result;\n//    }\n    \n    def strict[That](implicit bf : CanBuildTensorFrom[This,IndexDomain,Int,V,That]) = {\n      val builder = bf(inner, IndexDomain(size));\n      var i = 0;\n      for (v <- inner) {\n        if (filterFn(v)) {\n          builder(i) = v;\n          i += 1;\n        }\n      }\n      builder.result;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorCol.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain.IndexDomain;\n\nimport scalala.generic.collection.{CanAppendColumns};\nimport scalala.operators._;\n\nimport dense.{DenseVector,DenseVectorCol};\n\n/**\n * Implementation trait for a row vector.\n *\n * @author dramage\n */\ntrait VectorColLike[@specialized(Int,Long,Float,Double) V, +This<:VectorCol[V]]\nextends VectorLike[V,This] with Tensor1ColLike[Int,V,IndexDomain,This] {\n  override def t : VectorRow[V] =\n    new VectorRow.View(repr);\n\n  /** Returns a copy of this vector as a DenseVectorCol. */\n  override def toDense : DenseVectorCol[V] = {\n    val rv = DenseVector.zeros(length);\n    rv := repr;\n    rv;\n  }\n  \n  def toString(maxLines : Int = ScalalaConsole.terminalHeight - 3,\n               mkValueString : V=>String = buildMkValueString) : String = {\n    val showRows = if (length > maxLines) maxLines - 1 else length;\n    val newline = System.getProperty(\"line.separator\");\n    val rv = valuesIterator.take(showRows).map(mkValueString).mkString(newline);\n    \n    if (length > showRows) {\n      rv + newline + \"... (\"+(domain.size) +\" total)\";\n    } else {\n      rv;\n    }\n  }\n  \n  override def toString : String =\n    toString(maxLines = ScalalaConsole.terminalHeight - 3,\n             mkValueString = buildMkValueString);\n}\n\n/**\n * A vector shaped as a row.\n *\n * @author dramage\n */\ntrait VectorCol[@specialized(Int,Long,Float,Double) B]\nextends Vector[B] with Tensor1Col[Int,B] with VectorColLike[B,VectorCol[B]];\n\nobject VectorCol {\n  class View[V](override val inner : Vector[V])\n  extends VectorProxy[V,Vector[V]] with VectorCol[V]\n  with VectorLike[V,View[V]] {\n    override def repr : View[V] = this;\n  }\n\n//  implicit def canAppendMatrixColumns[V]\n//  : CanAppendColumns[Bound[V],Matrix[V],Matrix[V]]\n//  = new CanAppendColumns[Bound[V],Matrix[V],Matrix[V]] {\n//    override def apply(a : Bound[V], b : Matrix[V]) = {\n//      require(a.size == b.numRows, \"Arguments must have same number of rows\");\n//      implicit val sv = a.scalar;\n//      val builder = a.newBuilder[(Int,Int),V](TableDomain(a.size, 1+b.numCols));\n//      a.foreachNonZero((i,v) => builder((i,0)) = v);\n//      b.foreachNonZero((i,j,v) => builder((i,j+1)) = v);\n//      builder.result.asInstanceOf[Matrix[V]];\n//    }\n//  }\n\n//  implicit def canAppendVectorColumn[V]\n//  : CanAppendColumns[Bound[V],VectorCol[V],Matrix[V]]\n//  = new CanAppendColumns[Bound[V],VectorCol[V],Matrix[V]] {\n//    override def apply(a : Bound[V], b : VectorCol[V]) = {\n//      require(a.size == b.size, \"Arguments must have same number of rows\");\n//      implicit val sv = a.scalar;\n//      val builder = a.newBuilder[(Int,Int),V](TableDomain(a.size, 2));\n//      a.foreachNonZero((i,v) => builder((i,0)) = v);\n//      b.foreachNonZero((i,v) => builder((i,1)) = v);\n//      builder.result.asInstanceOf[Matrix[V]];\n//    }\n//  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorProxy.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport domain.IndexDomain;\n\n/**\n * Implementation trait for proxies to a Vector instance.\n *\n * @author dramage\n */\ntrait VectorProxyLike[@specialized(Int,Long,Float,Double) V, Inner<:Vector[V], +This<:Vector[V]]\nextends Tensor1ProxyLike[Int,V,IndexDomain,Inner,This] with VectorLike[V,This] {\n  override def length = inner.length;\n}\n\n/**\n * Proxy to a Vector instance.\n *\n * @author dramage\n */\ntrait VectorProxy[@specialized(Int,Long,Float,Double) V, Inner<:Vector[V]]\nextends Tensor1Proxy[Int,V,Inner] with Vector[V] with VectorProxyLike[V,Inner,VectorProxy[V,Inner]];\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorRow.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain.IndexDomain;\nimport generic.TensorBuilder;\n\nimport scalala.generic.collection.{CanSliceCol};\nimport scalala.operators._;\n\nimport dense.{DenseVector,DenseVectorRow};\n\n/**\n * Implementation trait for a row vector.\n *\n * @author dramage\n */\ntrait VectorRowLike[@specialized(Int,Long,Float,Double) V, +This<:VectorRow[V]]\nextends VectorLike[V,This] with Tensor1RowLike[Int,V,IndexDomain,This] {\n  \n  override def t : VectorCol[V] =\n    new VectorCol.View[V](repr);\n\n  /** Returns a copy of this vector as a DenseVectorRow. */\n  override def toDense : DenseVectorRow[V] = {\n    val rv = DenseVector.zeros(length).t;\n    rv := repr;\n    rv;\n  }\n\n  def toString(maxWidth : Int = ScalalaConsole.terminalWidth,\n               mkValueString : V=>String = buildMkValueString) : String = {\n    def colWidth(col : Int) = mkValueString(this(col)).length+2;\n\n    val colWidths = new scala.collection.mutable.ArrayBuffer[Int];\n    var col = 0;\n    while (col < size && colWidths.sum < maxWidth) {\n      colWidths += colWidth(col);\n      col += 1;\n    }\n    // make space for \"... (K total)\"\n    if (colWidths.size < length) {\n      while (colWidths.sum + maxWidth.toString.length + 12 >= maxWidth) {\n        colWidths.remove(colWidths.length - 1);\n      }\n    }\n\n    val newline = System.getProperty(\"line.separator\");\n\n    var rv = new StringBuilder;\n    for (col <- 0 until colWidths.length) {\n      val cell = mkValueString(this(col));\n      rv.append(cell);\n      rv.append(\" \" * (colWidths(col) - cell.length));\n      if (col == colWidths.length - 1) {\n        if (col < size - 1) {\n          rv.append(\"...\");\n          rv.append(\" (\");\n          rv.append(length);\n          rv.append(\" total)\");\n        }\n      }\n    }\n    rv.append(newline);\n    rv.toString;\n  }\n\n  override def toString =\n    toString(maxWidth = ScalalaConsole.terminalWidth,\n             mkValueString = buildMkValueString);\n}\n\n/**\n * A vector shaped as a row.\n *\n * @author dramage\n */\ntrait VectorRow[@specialized(Int,Long,Float,Double) V]\nextends Vector[V] with Tensor1Row[Int,V] with VectorRowLike[V,VectorRow[V]];\n\nobject VectorRow {\n  class View[V](override val inner : Vector[V])\n  extends VectorProxy[V,Vector[V]] with VectorRow[V]\n  with VectorLike[V,View[V]] {\n    override def repr : View[V] = this;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorSlice.scala",
    "content": "\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\n\nimport scalar.Scalar;\n\nimport domain.{IterableDomain,IndexDomain};\n\n/**\n * Implementation trait for a Vector view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait VectorSliceLike\n[@specialized(Int,Long) K, +D<:IterableDomain[K],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K,V],\n +This<:VectorSlice[K,V,Coll]]\nextends Tensor1SliceLike[K, D, Int, IndexDomain, V, Coll, This]\nwith VectorLike[V, This];\n\n/**\n * A Vector view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait VectorSlice\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K, V]]\nextends Tensor1Slice[K,Int,V,Coll] with Vector[V]\nwith VectorSliceLike[K, IterableDomain[K], V, Coll, VectorSlice[K, V, Coll]];\n\nobject VectorSlice {\n  abstract class FromKeySeq[K, V, +Coll <: Tensor[K, V]]\n  (override val underlying : Coll, keys : Seq[K])\n  (implicit override val scalar : Scalar[V])\n  extends VectorSlice[K, V, Coll] {\n    override def lookup(key : Int) = {\n      checkKey(key);\n      keys(key);\n    }\n    override def length = keys.size;\n  }\n}\n\n/**\n * Implementation trait for a VectorRow view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait VectorRowSliceLike\n[@specialized(Int,Long) K, +D<:IterableDomain[K],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K,V],\n +This<:VectorRowSlice[K,V,Coll]]\nextends VectorSliceLike[K, D, V, Coll, This]\nwith VectorRowLike[V, This];\n\n/**\n * A VectorRow view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait VectorRowSlice\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K, V]]\nextends VectorSlice[K,V,Coll] with VectorRow[V]\nwith VectorRowSliceLike[K, IterableDomain[K], V, Coll, VectorRowSlice[K, V, Coll]];\n\nobject VectorRowSlice {\n  class FromKeySeq[K, V:Scalar, +Coll<:Tensor[K, V]](underlying : Coll, keys : Seq[K])\n  extends VectorSlice.FromKeySeq[K,V,Coll](underlying, keys)\n  with VectorRowSlice[K,V,Coll] {\n    override def toDense = {\n      val rv = dense.DenseVectorRow.zeros[V](length);\n      rv := repr;\n      rv;\n    }\n  }\n}\n\n/**\n * Implementation trait for a VectorCol view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait VectorColSliceLike\n[@specialized(Int,Long) K, +D<:IterableDomain[K],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K,V],\n +This<:VectorColSlice[K,V,Coll]]\nextends VectorSliceLike[K, D, V, Coll, This]\nwith VectorColLike[V, This];\n\n/**\n * A VectorCol view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait VectorColSlice\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K, V]]\nextends VectorSlice[K,V,Coll] with VectorCol[V]\nwith VectorColSliceLike[K, IterableDomain[K], V, Coll, VectorColSlice[K, V, Coll]];\n\nobject VectorColSlice {\n  class FromKeySeq[K, V:Scalar, +Coll<:Tensor[K, V]](underlying : Coll, keys : Seq[K])\n  extends VectorSlice.FromKeySeq[K,V,Coll](underlying, keys)\n  with VectorColSlice[K,V,Coll] {\n    override def toDense = {\n      val rv = dense.DenseVectorCol.zeros[V](length);\n      rv := repr;\n      rv;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/ArrayArrayMatrix.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage dense;\n\nimport domain.TableDomain;\n\nimport scalala.scalar.Scalar;\n\n/**\n * A matrix backed by an array of arrays of values.\n * Assumes row-major storage.\n *\n * @author dramage\n */\nclass ArrayArrayMatrix[B](val data : Array[Array[B]])\n(implicit override val scalar : Scalar[B])\nextends mutable.Matrix[B] with mutable.MatrixLike[B,ArrayArrayMatrix[B]] {\n\n  if (data.map(_.length).distinct.size != 1) {\n    throw new IllegalArgumentException(\"All rows must be same length\");\n  }\n\n  override def numRows =\n    data.length;\n    \n  override def numCols =\n    data(0).length;\n\n  override def apply(i : Int, j : Int) =\n    data(i)(j);\n\n  override def update(i : Int, j : Int, v : B) =\n    data(i)(j) = v;\n}\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/DenseArrayTensor.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage dense;\n\nimport domain.{IterableDomain,IndexDomain,TableDomain};\nimport generic.TensorBuilder;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a tensor backed by a dense array of values.\n *\n * @author dramage\n */\ntrait DenseArrayTensorLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +D<:IterableDomain[K],\n +This<:DenseArrayTensor[K,V]]\nextends mutable.TensorLike[K,V,D,This] {\n  def data : Array[V];\n\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2])\n  : TensorBuilder[K2,V2,Tensor[K2,V2]] = domain match {\n    case that : IndexDomain => DenseVector.zeros[V2](that.size).asBuilder;\n    case that : TableDomain => DenseMatrix.zeros[V2](that.numRows, that.numCols).asBuilder;\n    case _ => super.newBuilder[K2,V2](domain);\n  }\n\n  override def foreachNonZeroValue[U](fn : (V=>U)) = {\n    foreachValue(fn);\n    true;\n  }\n}\n\n/**\n * Mutable tensor backed by a dense array of values.\n *\n * @author dramage\n */\ntrait DenseArrayTensor\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V]\nextends mutable.Tensor[K,V]\nwith DenseArrayTensorLike[K,V,IterableDomain[K],DenseArrayTensor[K,V]];\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/DenseMatrix.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage dense;\n\n\nimport domain.TableDomain;\n\nimport scalala.generic.collection._;\nimport scalala.scalar.Scalar;\nimport scalala.library.random.MersenneTwisterFast;\n\nimport scalala.operators._;\n\nimport org.netlib.blas._;\nimport org.netlib.lapack._;\nimport org.netlib.util.intW\nimport library.{LinearAlgebra, Random}\n;\n\n/**\n * A DenseMatrix is backed by an array of doubles, with each column\n * stored before the next column begins.\n *\n * @author dramage\n */\n@SerialVersionUID(1)\nclass DenseMatrix[@specialized(Int,Long,Float,Double) V]\n(override val numRows : Int, override val numCols : Int, data_ : Array[V])\n(implicit override val scalar : Scalar[V])\nextends DenseArrayTensor[(Int,Int),V] with DenseArrayTensorLike[(Int,Int),V,TableDomain,DenseMatrix[V]]\nwith mutable.Matrix[V] with mutable.MatrixLike[V,DenseMatrix[V]]\nwith Serializable {\n  override val data = data_ // workaround for https://lampsvn.epfl.ch/trac/scala/ticket/4013\n  \n  if (numRows * numCols != data_.length)\n    throw new IllegalArgumentException(\"data.length must equal numRows*numCols\");\n\n  /**\n   * Returns a view of this data matrix but with the given number of rows and columns.\n   * \n   * @throws IllegalArgumentException if the requested size does not match the current size.\n   */\n  def reshape(rows : Int, cols : Int) : DenseMatrix[V] = {\n    if (rows * cols != data.length) {\n      throw new IllegalArgumentException(\"Cannot reshape \"+numRows+\"x\"+numCols+\" to \"+rows+\"x\"+cols);\n    }\n    new DenseMatrix(rows, cols, data);\n  }\n\n  final def index(row : Int, col : Int) : Int = {\n    checkKey(row,col);\n    row + col * numRows;\n  }\n\n  final def unindex(index : Int) : (Int,Int) =\n    (rowIndex(index), colIndex(index));\n\n  final def rowIndex(index : Int) : Int =\n    (index % numRows);\n\n  final def colIndex(index : Int) : Int =\n    (index / numRows);\n\n  override def apply(row : Int, col : Int) =\n    data(index(row,col));\n    \n  /** Special case DenseVectorRow slice. */\n  def apply(row : Int, cols : Range) = {\n    checkKey(row,cols.last);\n    new DenseVectorRow(data, offset = index(row,cols.head),\n      stride = cols.step * numRows, length = cols.length)\n  }\n  \n  /** Special case DenseVectorCol slice. */\n  def apply(rows : Range, col : Int) = {\n    checkKey(rows.last,col);\n    new DenseVectorCol(data, offset = index(rows.head,col),\n      stride = rows.step, length = rows.length)\n  }\n\n  override def update(row : Int, col : Int, value : V) =\n    data(index(row,col)) = value;\n\n  override def foreachValue[U](f : (V)=>U) = {\n    var i = 0;\n    while (i < data.length) {\n      f(data(i));\n      i += 1;\n    }\n  }\n\n  override def foreachTriple[U](f : (Int,Int,V)=>U) = {\n    var i = 0;\n    while (i < data.length) {\n      f(rowIndex(i),colIndex(i),data(i));\n      i += 1;\n    }\n  }\n\n  /** Tranforms all values in this map by applying the given function. */\n  override def transformValues(f : V=>V) = {\n    var i = 0;\n    while (i < data.length) {\n      data(i) = f(data(i));\n      i += 1;\n    }\n  }\n\n  /** Tranforms all key value pairs in this map by applying the given function. */\n  override def transformTriples(f : (Int,Int,V)=>V) = {\n    var i = 0;\n    while (i < data.length) {\n      data(i) = f(rowIndex(i),colIndex(i),data(i));\n      i += 1;\n    }\n  }\n\n  def copy =\n    new DenseMatrix[V](numRows, numCols, data.clone);\n}\n\nobject DenseMatrix extends DenseMatrixConstructors {\n\n  /** Any matrix multiplied by dense is dense. */\n  implicit def canBuildDenseMatrixMulRight[@specialized A, VA, VB, RV]\n  (implicit viewA : A=>scalala.tensor.Matrix[VA], mul : BinaryOp[VA,VB,OpMul,RV], s : Scalar[RV])\n  : CanBuildTensorForBinaryOp[A,DenseMatrix[VB],TableDomain,(Int,Int),RV,OpMulMatrixBy,DenseMatrix[RV]]\n  = new CanBuildTensorForBinaryOp[A,DenseMatrix[VB],TableDomain,(Int,Int),RV,OpMulMatrixBy,DenseMatrix[RV]] {\n    override def apply(a : A, b : DenseMatrix[VB], domain : TableDomain) =\n      DenseMatrix.zeros[RV](domain._1.size, domain._2.size).asBuilder.\n        asInstanceOf[generic.TensorBuilder[(Int, Int),RV,DenseMatrix[RV]]];\n  }\n\n  //\n  // Capabilities\n  //\n\n  class DenseMatrixCanSliceRow[@specialized V:Scalar]\n  extends CanSliceRow[DenseMatrix[V],Int,DenseVectorRow[V]] {\n    override def apply(from : DenseMatrix[V], i : Int) =\n      new DenseVectorRow[V](from.data, length = from.numCols, offset = i, stride = from.numRows);\n  }\n  \n  class DenseMatrixCanSliceCol[@specialized V:Scalar]\n  extends CanSliceCol[DenseMatrix[V],Int,DenseVectorCol[V]] {\n    override def apply(from : DenseMatrix[V], j : Int) =\n      new DenseVectorCol[V](from.data, length = from.numRows, offset = j * from.numRows, stride = 1);\n  }\n\n  class DenseMatrixCanMapValues[@specialized(Int,Long,Float,Double) V, @specialized(Int,Long,Float,Double) R:ClassManifest:Scalar]\n  extends CanMapValues[DenseMatrix[V],V,R,DenseMatrix[R]] {\n    override def map(from : DenseMatrix[V], fn : (V=>R)) = {\n      val data = new Array[R](from.data.length);\n      var i = 0;\n      while (i < data.length) {\n        data(i) = fn(from.data(i));\n        i += 1;\n      }\n      new DenseMatrix[R](from.numRows, from.numCols, data);\n    }\n\n    override def mapNonZero(from : DenseMatrix[V], fn : (V=>R)) =\n      map(from, fn);\n  }\n\n  class DenseMatrixCanMapKeyValuePairs[@specialized(Int,Long,Float,Double) V, @specialized(Int,Long,Float,Double) R:ClassManifest:Scalar]\n  extends CanMapKeyValuePairs[DenseMatrix[V],(Int,Int),V,R,DenseMatrix[R]] {\n    override def map(from : DenseMatrix[V], fn : (((Int,Int),V)=>R)) = {\n      val data = new Array[R](from.data.length);\n      var i = 0;\n      while (i < data.length) {\n        data(i) = fn(from.unindex(i), from.data(i));\n        i += 1;\n      }\n      new DenseMatrix(from.numRows, from.numCols, data);\n    }\n    \n    override def mapNonZero(from : DenseMatrix[V], fn : (((Int,Int),V)=>R)) =\n      map(from, fn);\n  }\n\n  implicit def mkDenseMatrixCanSliceRow[@specialized V:Scalar] =\n    new DenseMatrixCanSliceRow[V];\n\n  implicit def mkDenseMatrixCanSliceCol[@specialized V:Scalar] =\n    new DenseMatrixCanSliceCol[V];\n    \n  implicit def mkDenseMatrixCanMapValues[V,R:ClassManifest:Scalar] =\n    new DenseMatrixCanMapValues[V,R];\n  \n  implicit def mkDenseMatrixCanMapKeyValuePairs[V,R:ClassManifest:Scalar] =\n    new DenseMatrixCanMapKeyValuePairs[V,R];\n\n  implicit object DenseMatrixCanSliceRowI extends DenseMatrixCanSliceRow[Int];\n  implicit object DenseMatrixCanSliceRowL extends DenseMatrixCanSliceRow[Long];\n  implicit object DenseMatrixCanSliceRowF extends DenseMatrixCanSliceRow[Float];\n  implicit object DenseMatrixCanSliceRowD extends DenseMatrixCanSliceRow[Double];\n\n  implicit object DenseMatrixCanSliceColI extends DenseMatrixCanSliceCol[Int];\n  implicit object DenseMatrixCanSliceColL extends DenseMatrixCanSliceCol[Long];\n  implicit object DenseMatrixCanSliceColF extends DenseMatrixCanSliceCol[Float];\n  implicit object DenseMatrixCanSliceColD extends DenseMatrixCanSliceCol[Double];\n  \n  implicit object DenseMatrixCanMapValuesDD extends DenseMatrixCanMapValues[Double,Double];\n  implicit object DenseMatrixCanMapValuesII extends DenseMatrixCanMapValues[Int,Int];\n  implicit object DenseMatrixCanMapValuesID extends DenseMatrixCanMapValues[Int,Double];\n\n\n  //\n  // BLAS and LAPACK routines\n  //\n  \n  implicit object DenseMatrixDMulDenseMatrixD\n  extends BinaryOp[DenseMatrix[Double],DenseMatrix[Double],OpMulMatrixBy,DenseMatrix[Double]] {\n    def opType = OpMulMatrixBy;\n    def apply(a : DenseMatrix[Double], b : DenseMatrix[Double]) = {\n      val rv = DenseMatrix.zeros[Double](a.numRows, b.numCols);\n      // System.err.println(\"BLAS!\");\n      BLAS.getInstance().dgemm(\"n\", \"n\",\n        rv.numRows, rv.numCols, a.numCols,\n        1.0, a.data, a.numRows, b.data, a.numCols,\n        0.0, rv.data, a.numRows);\n      rv;\n    }\n  }\n\n  implicit object DenseMatrixDMulDenseVectorColD\n  extends BinaryOp[DenseMatrix[Double],DenseVectorCol[Double],OpMulMatrixBy,DenseVectorCol[Double]] {\n    def opType = OpMulMatrixBy;\n    def apply(a : DenseMatrix[Double], b : DenseVectorCol[Double]) = {\n      val rv = DenseVectorCol.zeros[Double](a.numRows);\n      // System.err.println(\"BLAS!\");\n      org.netlib.blas.Dgemv.dgemv(\"n\",\n        a.numRows, a.numCols,\n        1.0, a.data, 0, a.numRows,\n             b.data, b.offset, b.stride,\n        0.0, rv.data, rv.offset, rv.stride);\n      rv;\n    }\n  }\n\n  implicit object DenseMatrixCanSolveDenseMatrix\n  extends BinaryOp[DenseMatrix[Double],DenseMatrix[Double],OpSolveMatrixBy,DenseMatrix[Double]] {\n    override def opType = OpSolveMatrixBy;\n    override def apply(A : DenseMatrix[Double], V : DenseMatrix[Double]) = {\n      require(A.numRows == V.numRows,\n              \"Non-conformant matrix sizes\");\n\n      // from MTJ 0.9.9\n      if (A.numRows == A.numCols) {\n        // square: LUSolve\n        val X = V.copy;\n        LUSolve(X,A);\n        X;\n      } else {\n        // non-square: QRSolve\n        val X = DenseMatrix.zeros[Double](A.numCols, V.numCols);\n        QRSolve(X,A,V,false);\n        X;\n      }\n    }\n\n    /** X := A \\ X */\n    def LUSolve(X : DenseMatrix[Double], A : DenseMatrix[Double]) = {\n      val piv = new Array[Int](A.numRows);\n\n      val info = new intW(0);\n      LAPACK.getInstance().dgesv(\n        A.numRows, X.numCols,\n        A.data.clone(), math.max(1, A.numRows),\n        piv,\n        X.data, math.max(1, A.numRows), info);\n\n      if (info.`val` > 0)\n        throw new MatrixSingularException();\n      else if (info.`val` < 0)\n        throw new IllegalArgumentException();\n\n      X;\n    }\n\n    /** X := A \\ V */\n    def QRSolve(X : DenseMatrix[Double], A : DenseMatrix[Double], V : DenseMatrix[Double], transpose : Boolean) = {\n      require(X.numRows == A.numCols, \"Wrong number of rows in return value\");\n      require(X.numCols == V.numCols, \"Wrong number of rows in return value\");\n\n      val nrhs = V.numCols;\n      \n      // allocate temporary solution matrix\n      val Xtmp = DenseMatrix.zeros[Double](math.max(A.numRows, A.numCols), nrhs);\n      val M = if (!transpose) A.numRows else A.numCols;\n      for (j <- 0 until nrhs; i <- 0 until M) { Xtmp(i,j) = V(i,j); }\n\n      val newData = A.data.clone();\n\n      // query optimal workspace\n      val queryWork = new Array[Double](1);\n      val queryInfo = new intW(0);\n      LAPACK.getInstance().dgels(\n        if (!transpose) \"N\" else \"T\",\n        A.numRows, A.numCols, nrhs,\n        newData, math.max(1,A.numRows),\n        Xtmp.data, math.max(1,math.max(A.numRows,A.numCols)),\n        queryWork, -1, queryInfo);\n\n      // allocate workspace\n      val work = {\n        val lwork = {\n          if (queryInfo.`val` != 0)\n            math.max(1, math.min(A.numRows, A.numCols) + math.max(math.min(A.numRows, A.numCols), nrhs));\n          else\n            math.max(queryWork(0).toInt, 1);\n        }\n        new Array[Double](lwork);\n      }\n\n      // compute factorization\n      val info = new intW(0);\n      LAPACK.getInstance().dgels(\n        if (!transpose) \"N\" else \"T\",\n        A.numRows, A.numCols, nrhs,\n        newData, math.max(1,A.numRows),\n        Xtmp.data, math.max(1,math.max(A.numRows,A.numCols)),\n        work, work.length, info);\n\n      if (info.`val` < 0)\n        throw new IllegalArgumentException;\n\n      // extract solution\n      val N = if (!transpose) A.numCols else A.numRows;\n      for (j <- 0 until nrhs; i <- 0 until N) X(i,j) = Xtmp(i,j);\n\n      X;\n    }\n  }\n\n  implicit object DenseMatrixCanSolveDenseVector\n  extends BinaryOp[DenseMatrix[Double],DenseVectorCol[Double],OpSolveMatrixBy,DenseVectorCol[Double]] {\n    override def opType = OpSolveMatrixBy;\n    override def apply(a : DenseMatrix[Double], b : DenseVectorCol[Double]) = {\n      val rv = a \\ new DenseMatrix[Double](b.size, 1, b.data);\n      new DenseVectorCol[Double](rv.data);\n    }\n  }\n}\n\n/**\n * Constructors for dense matrices.\n * \n * @author dramage\n */\ntrait DenseMatrixConstructors {\n  /** Constructs a dense matrix for the given table domain. */\n  def apply[V:Scalar](domain : TableDomain) =\n    zeros[V](domain._1.size, domain._2.size);\n\n  /** Static constructor for a literal matrix. */\n  def apply[R,V](rows : R*)(implicit rl : LiteralRow[R,V], scalar : Scalar[V]) = {\n    val nRows = rows.length;\n    val nCols = rl.length(rows(0));\n    val rv = zeros(nRows, nCols);\n    for ((row,i) <- rows.zipWithIndex) {\n      rl.foreach(row, ((j, v) => rv(i,j) = v));\n    }\n    rv;\n  }\n\n  /** Creates a dense matrix of the given value repeated of the requested size. */\n  def fill[V:Scalar](rows : Int, cols : Int)(value : V) = {\n    implicit val mf = implicitly[Scalar[V]].manifest;\n    new DenseMatrix[V](rows, cols, Array.fill(rows * cols)(value));\n  }\n\n  /** Creates a dense matrix of zeros of the requested size. */\n  def zeros[V](rows : Int, cols : Int)(implicit s : Scalar[V]) = {\n    if (s.isPrimitive) {\n      new DenseMatrix(rows, cols, s.manifest.newArray(rows * cols));\n    } else {\n      fill(rows, cols)(s.zero);\n    }\n  }\n\n  /** Creates a dense matrix of zeros of the requested size. */\n  def ones[V:Scalar](rows : Int, cols : Int) =\n    fill(rows, cols)(implicitly[Scalar[V]].one);\n\n  /** Creates an identity matrix with size rows and columns. */\n  def eye[V](size : Int)(implicit scalar : Scalar[V]) = {\n    val rv = zeros(size, size);\n    for (i <- 0 until size) {\n      rv(i,i) = scalar.one;\n    }\n    rv;\n  }\n\n  /** Creates a non-square \"identity\" matrix of the given size. */\n  def eye[V](rows : Int, cols : Int)(implicit scalar : Scalar[V]) = {\n    val rv = zeros(rows, cols);\n    for (i <- 0 until scala.math.min(rows, cols)) {\n      rv(i, i) = scalar.one;\n    }\n    rv;\n  }\n\n  /** Tabulate a matrix from a function from row,col position to value. */\n  def tabulate[V:Scalar](rows : Int, cols : Int)(fn : (Int, Int) => V) = {\n    implicit val mf = implicitly[Scalar[V]].manifest;\n    new DenseMatrix(rows, cols, Array.tabulate(rows * cols)(i => fn(i % rows, i / rows)));\n  }\n\n  /** Horizontally tiles some matrices. They must have the same number of rows */\n  def horzcat[V:Scalar](matrices: Matrix[V]*) = {\n    if(matrices.isEmpty) zeros[V](0,0)\n    else {\n      require(matrices.forall(m => m.numRows == matrices(0).numRows),\"Not all matrices have the same number of rows\");\n      val numCols = matrices.foldLeft(0)(_ + _.numCols);\n      val numRows = matrices(0).numRows;\n      val res = DenseMatrix.zeros[V](numRows,numCols);\n      var offset = 0;\n      for(m <- matrices) {\n        res(0 until numRows,(offset) until (offset + m.numCols)) := m;\n        offset+= m.numCols;\n      }\n      res\n    }\n  }\n\n  /** Vertically tiles some matrices. They must have the same number of columns */\n  def vertcat[V:Scalar](matrices: Matrix[V]*) = {\n    if(matrices.isEmpty) zeros[V](0,0)\n    else {\n      require(matrices.forall(m => m.numCols == matrices(0).numCols),\"Not all matrices have the same number of columns\");\n      val numRows = matrices.foldLeft(0)(_ + _.numRows);\n      val numCols = matrices(0).numCols;\n      val res = DenseMatrix.zeros[V](numRows,numCols);\n      var offset = 0;\n      for(m <- matrices) {\n        res((offset) until (offset + m.numRows),0 until numCols) := m;\n        offset+= m.numRows;\n      }\n      res\n    }\n  }\n\n  /** A vector of the given size with uniform random values between 0 and 1. */\n  def rand(rows : Int, cols : Int, mt : MersenneTwisterFast = Random.mt) = mt.synchronized {\n    tabulate(rows, cols)((i,j) => mt.nextDouble);\n  }\n\n  /**\n   * A vector of the given size with normally distributed random values\n   * with mean 0 and standard deviation 1.\n   */\n  def randn(rows : Int, cols : Int, mt : MersenneTwisterFast = Random.mt) = mt.synchronized {\n    tabulate(rows, cols)((i,j) => mt.nextGaussian);\n  }\n\n  /** A vector of the given size of random integers in the range [0..max). */\n  def randi(imax : Int, rows : Int, cols : Int, mt : MersenneTwisterFast = Random.mt) = mt.synchronized {\n    tabulate(rows, cols)((i,j) => mt.nextInt(imax));\n  }\n\n    /**\n   * Computes a matrix whose columns represent samples drawn from a multivariate\n   * Gaussian distribution obeying both the given mean `mu' and covariance\n   * matrix `Sigma'.\n   *\n   * @throws NotConvergedException in case of a malformed covariance matrix\n   */\n  def randn(mu: Vector[Double], sigma: Matrix[Double], numSamples: Int)(implicit mt : MersenneTwisterFast): DenseMatrix[Double] = {\n    require(numSamples >= 1, \"Must request at least one sample\");\n    require(sigma.isSymmetric, \"Sigma must be symmetric\");\n    require(mu.size == sigma.numCols, \"mu must be same length as sigma\");\n\n    // Assuming multivariate samples with zero mean, the general form of\n    // the covariance matrix is X X^T where the scale factor 1/(N-1) has\n    // been left out for improved readabilty.\n    // Let Y = AX, then Y Y^T = (AX) (AX)^T = A (X X^T) A^T.\n    // In case of a random matrix X where each element of X has been\n    // drawn from a standard normal distribution, and where thus all\n    // random variables are i.i.d. it holds that X X^T = I (identity)\n    // yielding A (X X^T) A^T = A A^T.\n    // So we're looking for a \"square root\" A of the given covariance\n    // matrix Sigma:\n    val sqrtSigma = LinearAlgebra.cholesky(sigma)\n    val samples: DenseMatrix[Double] =\n      sqrtSigma * DenseMatrix.randn(mu.size, numSamples, mt)\n    // Due to the row-major storage order of (dense) matrices it's probably\n    // best to use row-wise scalar addition instead of column-wise vector\n    // addition:\n    for (i <- 0 until mu.size)\n      samples(i, ::) += mu(i)\n\n    samples\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/DenseVector.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage dense;\n\nimport domain.{IterableDomain,IndexDomain};\n\nimport scalala.generic.collection._;\nimport scalala.scalar.Scalar;\nimport scalala.library.random.MersenneTwisterFast;\nimport scalala.library.Random;\nimport scalala.operators._\nimport bundles.MutableInnerProductSpace\nimport java.util.Arrays\n\n/**\n * A vector backed by a dense array.\n *\n * @author dramage\n */\n@SerialVersionUID(1)\ntrait DenseVector[@specialized(Int,Long,Float,Double) V]\nextends mutable.Vector[V] with mutable.VectorLike[V,DenseVector[V]]\nwith DenseArrayTensor[Int,V] with DenseArrayTensorLike[Int,V,IndexDomain,DenseVector[V]]\n{ self =>\n\n  /** Starting offset within data array. */\n  val offset : Int;\n\n  /** Gap between successive elements in data array. */\n  val stride : Int;\n\n  override def apply(key : Int) =\n    data(offset + key * stride);\n\n  override def update(key : Int, value : V) =\n    data(offset + key * stride) = value;\n\n  override def foreachPair[U](fn : ((Int,V)=>U)) = {\n    var i = 0;\n    var k = offset;\n    while (i < length) {\n      fn(i, data(k));\n      i += 1;\n      k += stride;\n    }\n  }\n\n  override def foreachValue[U](fn : (V=>U)) = {\n    var i = 0;\n    var k = offset;\n    while (i < length) {\n      fn(data(k));\n      i += 1;\n      k += stride;\n    }\n  }\n\n  override def transformPairs(fn : (Int,V)=>V) = {\n    var i = 0;\n    var k = offset;\n    while (i < length) {\n      data(k) = fn(i,data(k));\n      i += 1;\n      k += stride;\n    }\n  }\n\n  override def transformValues(fn : V=>V) = {\n    var i = 0;\n    var k = offset;\n    while (i < length) {\n      data(k) = fn(data(k));\n      i += 1;\n      k += stride;\n    }\n  }\n\n  /** Returns a view of this vector as a row. */\n  override def asRow : DenseVectorRow[V] =\n    new DenseVectorRow(this.data, offset, stride, length);\n\n  /** Returns a view of this vector as a column.  */\n  override def asCol : DenseVectorCol[V] =\n    new DenseVectorCol(this.data, offset, stride, length);\n}\n\ntrait LowPriorityDenseImplicits {\n  class CanJoinDenseWithNonDense[\n    @specialized(Int,Long,Float,Double) V1,\n    @specialized(Int,Long,Float,Double) V2,\n    DV[V]<:DenseVector[V]] extends CanJoin[DV[V1], Vector[V2], Int, V1, V2] {\n    def joinAll[RV](a: DV[V1], b: Vector[V2], fn: (Int, V1, V2) => RV) {\n      a.checkDomain(b.domain)\n      for( (i,v2) <- b.pairs) {\n        fn(i,a(i),v2)\n      }\n\n    }\n\n    def joinBothNonZero[RV](a: DV[V1], b: Vector[V2], fn: (Int, V1, V2) => RV) {\n      joinAll(a,b,fn)\n    }\n\n    def joinEitherNonZero[RV](a: DV[V1], b: Vector[V2], fn: (Int, V1, V2) => RV) {\n      joinAll(a,b,fn)\n    }\n  }\n\n  /** Optimized base class for joining dense columns. */\n    implicit def canJoinDenseVectorColsWithNonDense[V1, V2]\n  : CanJoinDenseWithNonDense[V1, V2, DenseVectorCol] =\n  new CanJoinDenseWithNonDense[V1, V2, DenseVectorCol];\n\n  /** Optimized base class for joining dense rows. */\n  implicit def canJoinDenseVectorRowsWithNonDense[V1, V2]\n  : CanJoinDenseWithNonDense[V1, V2, DenseVectorRow] =\n  new CanJoinDenseWithNonDense[V1, V2, DenseVectorRow];\n\n\n}\n\nobject DenseVector extends DenseVectorConstructors with LowPriorityDenseImplicits {\n  //\n  // Generic optimized routines\n  //\n\n  class GenericDenseVectorRowBase[@specialized V:Scalar:Manifest] {\n    def create(length : Int) = new DenseVectorRow(new Array[V](length));\n  }\n\n  class GenericDenseVectorColBase[@specialized V:Scalar:Manifest] {\n    def create(length : Int) = new DenseVectorCol(new Array[V](length));\n  }\n\n  class GenericDenseVectorBase[@specialized V:Scalar:Manifest] {\n    def create(length : Int) = new DenseVectorCol(new Array[V](length));\n  }\n\n\n\n  /** Optimized base class for joining two dense tensors. */\n  class CanJoinDenseVectors[\n   @specialized(Int,Long,Float,Double) V1,\n   @specialized(Int,Long,Float,Double) V2,\n   DV[V]<:DenseVector[V]]\n  extends CanJoin[DV[V1], DV[V2], Int, V1, V2] {\n    override def joinAll[RV](a : DV[V1], b : DV[V2], fn : (Int,V1,V2)=>RV) = {\n      // System.err.println(\"DENSE!\");\n      a.checkDomain(b.domain);\n      var i = 0;\n      var k1 = a.offset;\n      var k2 = b.offset;\n      while (i < a.length) {\n        fn(i, a.data(k1), b.data(k2));\n        i += 1;\n        k1 += a.stride;\n        k2 += b.stride;\n      }\n    }\n\n    override def joinBothNonZero[RV](a : DV[V1], b : DV[V2], fn : (Int,V1,V2)=>RV) =\n      joinAll(a,b,fn);\n\n    override def joinEitherNonZero[RV](a : DV[V1], b : DV[V2], fn : (Int,V1,V2)=>RV) =\n      joinAll(a,b,fn);\n  }\n\n  /** Optimized base class for joining dense columns. */\n  implicit def canJoinDenseVectorCols[V1, V2]\n  : CanJoinDenseVectors[V1, V2, DenseVectorCol] =\n  new CanJoinDenseVectors[V1, V2, DenseVectorCol];\n\n  /** Optimized base class for joining dense rows. */\n  implicit def canJoinDenseVectorRows[V1, V2]\n  : CanJoinDenseVectors[V1, V2, DenseVectorRow] =\n  new CanJoinDenseVectors[V1, V2, DenseVectorRow];\n\n  /** Optimized base class for mapping a dense tensor. */\n  trait CanMapValuesDenseVector\n  [@specialized V, @specialized RV, DV[V]<:DenseVector[V]]\n  extends CanMapValues[DV[V],V,RV,DV[RV]] {\n    def create(length : Int) : DV[RV];\n\n    override def map(from : DV[V], fn : (V=>RV)) = {\n      // System.err.println(\"DENSE!\");\n      val rv = create(from.length);\n      var i = 0;\n      var k = from.offset;\n      while (i < from.length) {\n        rv.data(i) = fn(from.data(k));\n        i += 1;\n        k += from.stride;\n      }\n      rv;\n    }\n\n    override def mapNonZero(from : DV[V], fn : (V=>RV)) =\n      map(from, fn);\n  }\n\n  /** Optimized base class for mapping dense columns. */\n  implicit def canMapValuesDenseVectorCols[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanMapValuesDenseVector[V, RV, DenseVectorCol] =\n    new GenericDenseVectorColBase with CanMapValuesDenseVector[V, RV, DenseVectorCol];\n\n  /** Optimized base class for mapping dense rows. */\n  implicit def canMapValuesDenseVectorRows[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanMapValuesDenseVector[V, RV, DenseVectorRow] =\n    new GenericDenseVectorRowBase with CanMapValuesDenseVector[V, RV, DenseVectorRow];\n\n  /** optimized for just mapping densevectors */\n  implicit def canMapValuesDenseVectors[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanMapValuesDenseVector[V, RV, DenseVector] =\n    new GenericDenseVectorColBase with CanMapValuesDenseVector[V, RV, DenseVector];\n\n  /** Optimized base class for mapping a dense tensor. */\n  trait CanZipMapValuesDenseVector\n  [@specialized V, @specialized RV, DV[V]<:DenseVector[V]]\n    extends CanZipMapValues[DV[V],V,RV,DV[RV]] {\n    def create(length : Int) : DV[RV];\n\n    /**Maps all corresponding values from the two collection. */\n    def map(from: DV[V], from2: DV[V], fn: (V, V) => RV) = {\n      require(from.length == from2.length, \"Vector lengths must match!\")\n      val result = create(from.length)\n      var i = 0\n      while (i < from.length) {\n        result(i) = fn(from(i), from2(i))\n        i += 1\n      }\n      result\n    }\n  }\n\n  /** Optimized base class for mapping dense columns. */\n  implicit def canZipMapValuesDenseVectorCols[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanZipMapValuesDenseVector[V, RV, DenseVectorCol] =\n    new GenericDenseVectorColBase with CanZipMapValuesDenseVector[V, RV, DenseVectorCol];\n\n  /** Optimized base class for mapping dense rows. */\n  implicit def canZipMapValuesDenseVectorRows[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanZipMapValuesDenseVector[V, RV, DenseVectorRow] =\n    new GenericDenseVectorRowBase with CanZipMapValuesDenseVector[V, RV, DenseVectorRow];\n\n  /** optimized for just mapping densevectors */\n  implicit def canZipMapValuesDenseVectors[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanZipMapValuesDenseVector[V, RV, DenseVector] =\n    new GenericDenseVectorColBase with CanZipMapValuesDenseVector[V, RV, DenseVector];\n\n\n\n  /** Optimized base class for mapping a dense tensor. */\n  trait CanMapKeyValuePairsDenseVector\n  [@specialized V, @specialized RV, DV[V]<:DenseVector[V]]\n  extends CanMapKeyValuePairs[DV[V],Int,V,RV,DV[RV]] {\n    def create(length : Int) : DV[RV];\n\n    override def map(from : DV[V], fn : (Int,V)=>RV) = {\n      // System.err.println(\"DENSE!\");\n      val rv = create(from.length);\n      var i = 0;\n      var k = from.offset;\n      while (i < from.length) {\n        rv.data(i) = fn(i, from.data(k));\n        i += 1;\n        k += from.stride;\n      }\n      rv;\n    }\n\n    override def mapNonZero(from : DV[V], fn : (Int,V)=>RV) =\n      map(from, fn);\n  }\n\n  /** Optimized base class for mapping dense columns. */\n  implicit def canMapKeyValuePairsDenseVectorCols[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanMapKeyValuePairsDenseVector[V, RV, DenseVectorCol] =\n  new GenericDenseVectorColBase with CanMapKeyValuePairsDenseVector[V, RV, DenseVectorCol];\n\n  /** Optimized base class for mapping dense rows. */\n  implicit def canMapKeyValuePairsDenseVectorRows[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanMapKeyValuePairsDenseVector[V, RV, DenseVectorRow] =\n  new GenericDenseVectorRowBase with CanMapKeyValuePairsDenseVector[V, RV, DenseVectorRow];\n\n    implicit def canMapKeyValuePairsDenseVector[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanMapKeyValuePairsDenseVector[V, RV, DenseVector] =\n  new GenericDenseVectorColBase with CanMapKeyValuePairsDenseVector[V, RV, DenseVector];\n\n  /** Optimized base class for creating zeros */\n  trait CanCreateZerosDenseVector\n  [@specialized V, @specialized RV, DV[V]<:DenseVector[V]]\n    extends CanCreateZerosLike[DV[V],DV[RV]] {\n    def create(length : Int) : DV[RV];\n    def apply(v1: DV[V]) = create(v1.length);\n  }\n\n\n  implicit def canCreateZerosDenseVector[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanCreateZerosDenseVector[V, RV, DenseVector] =\n    new GenericDenseVectorColBase with CanCreateZerosDenseVector[V, RV, DenseVector];\n\n    /** Optimized base class for mapping dense columns. */\n  implicit def canCreateZerosDenseVectorCols[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanCreateZerosDenseVector[V, RV, DenseVectorCol] =\n  new GenericDenseVectorColBase with CanCreateZerosDenseVector[V, RV, DenseVectorCol];\n\n  /** Optimized base class for mapping dense rows. */\n  implicit def canCreateZerosDenseVectorRows[@specialized V, @specialized RV:Scalar:Manifest]\n  : CanCreateZerosDenseVector[V, RV, DenseVectorRow] =\n  new GenericDenseVectorRowBase with CanCreateZerosDenseVector[V, RV, DenseVectorRow];\n\n\n  /** Optimized base class for copying zeros */\n  class CanCopyDenseVectorRow[@specialized V:Scalar:ClassManifest] extends CanCopy[DenseVectorRow[V]] {\n    def apply(v1: DenseVectorRow[V]) = {\n      new DenseVectorRow(Array.tabulate(v1.length)(i => v1(i)));\n    }\n  }\n\n  class CanCopyDenseVector[@specialized V:Scalar:ClassManifest] extends CanCopy[DenseVector[V]] {\n    def apply(v1: DenseVector[V]) = {\n      new DenseVectorCol(Array.tabulate(v1.length)(i => v1(i)));\n    }\n  }\n\n  class CanCopyDenseVectorCol[@specialized V:Scalar:ClassManifest] extends CanCopy[DenseVectorCol[V]] {\n    def apply(v1: DenseVectorCol[V]) = {\n      new DenseVectorCol(Array.tabulate(v1.length)(i => v1(i)));\n    }\n  }\n\n    /** Optimized base class for mapping dense columns. */\n  implicit def canCopyDenseVectorCols[@specialized V:Scalar:Manifest] = new CanCopyDenseVectorCol[V];\n\n  /** Optimized base class for mapping dense rows. */\n  implicit def canCopyDenseVectorRows[@specialized V:Scalar:Manifest] = new CanCopyDenseVectorRow[V];\n\n\n\n  //\n  // Specialized objects for generic routines\n  //\n\n  implicit object CanJoinDVCDDVCD extends CanJoinDenseVectors[Double,Double,DenseVectorCol];\n\n  implicit object CanJoinDVRDDVRD extends CanJoinDenseVectors[Double,Double,DenseVectorRow];\n\n  implicit object CanMapValuesDV extends GenericDenseVectorBase[Double]\n  with CanMapValuesDenseVector[Double,Double,DenseVector];\n\n  implicit object CanMapValuesDVCDDVCD extends GenericDenseVectorColBase[Double]\n  with CanMapValuesDenseVector[Double,Double,DenseVectorCol];\n\n  implicit object CanMapValuesDVRDDVRD extends GenericDenseVectorRowBase[Double]\n  with CanMapValuesDenseVector[Double,Double,DenseVectorRow];\n\n  implicit object CanMapKeyValuePairsDVCDDVCD extends GenericDenseVectorColBase[Double]\n  with CanMapKeyValuePairsDenseVector[Double,Double,DenseVectorCol];\n\n  implicit object CanMapKeyValuePairsDVRDDVRD extends GenericDenseVectorRowBase[Double]\n  with CanMapKeyValuePairsDenseVector[Double,Double,DenseVectorRow];\n\n  //\n  // BLAS routines\n  //\n\n  /** BLAS-optimized scala multiply. */\n  implicit object DenseVectorDMulDInto\n  extends BinaryUpdateOp[DenseVector[Double],Double,OpMul] {\n    override def opType = OpMul;\n    override def apply(a : DenseVector[Double], b : Double) = {\n      // System.err.println(\"BLAS!\");\n      org.netlib.blas.Dscal.dscal(a.length, b, a.data, a.offset, a.stride);\n    }\n  }\n\n  /** BLAS-optimized vector addition. */\n  implicit object DenseVectorDAddDenseVectorDInto\n  extends BinaryUpdateOp[DenseVector[Double],DenseVector[Double],OpAdd] {\n    override def opType = OpAdd;\n    override def apply(a : DenseVector[Double], b : DenseVector[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n      // System.err.println(\"BLAS!\");\n      org.netlib.blas.Daxpy.daxpy(\n        a.length, 1.0, b.data, b.offset, b.stride, a.data, a.offset, a.stride);\n    }\n  }\n\n    /** BLAS-optimized vector subtraction. */\n  implicit object DenseVectorDSubDenseVectorDInto\n  extends BinaryUpdateOp[DenseVector[Double],DenseVector[Double],OpSub] {\n    override def opType = OpSub;\n    override def apply(a : DenseVector[Double], b : DenseVector[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n      // System.err.println(\"BLAS!\");\n      org.netlib.blas.Daxpy.daxpy(\n        a.length, -1.0, b.data, b.offset, b.stride, a.data, a.offset, a.stride);\n    }\n  }\n\n  /** BLAS-optimized vector-vector inner product. */\n  implicit object DenseVectorDInnerMulDenseVectorD\n  extends BinaryOp[DenseVectorRow[Double],DenseVectorCol[Double],OpMulRowVectorBy,Double] {\n    override def opType = OpMulRowVectorBy;\n    override def apply(a : DenseVectorRow[Double], b : DenseVectorCol[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n      // System.err.println(\"BLAS!\");\n      org.netlib.blas.Ddot.ddot(\n        a.length, a.data, a.offset, a.stride, b.data, b.offset, b.stride);\n    }\n  }\n\n\n  /** BLAS-optimized forwarding calls from UpdateOp to Op */\n  implicit def binaryOpFromBinaryUpdateOp[DV<:DenseVector[Double],Other,Op<:OpType](implicit copy: CanCopy[DV], op: BinaryUpdateOp[DV,Other,Op]) = {\n    new BinaryOp[DV,Other,Op,DV] {\n      override def opType = op.opType;\n      override def apply(a : DV, b : Other) = {\n        val c = copy(a)\n        op(c,b)\n        c\n      }\n    }\n  }\n\n  implicit def denseVectorColVSpace:MutableInnerProductSpace[Double,DenseVectorCol[Double]] = {\n    MutableInnerProductSpace.make[Double,DenseVectorCol[Double]]\n  };\n\n  implicit def denseVectorRowVSpace:MutableInnerProductSpace[Double,DenseVectorRow[Double]] = {\n    MutableInnerProductSpace.make[Double,DenseVectorRow[Double]]\n  };\n\n  implicit def denseVectorVSpace:MutableInnerProductSpace[Double,DenseVector[Double]] = {\n    MutableInnerProductSpace.make[Double,DenseVector[Double]]\n  };\n\n}\n\n/**\n * DenseVectors as a row.\n *\n * @author dramage\n */\nfinal class DenseVectorRow[@specialized(Int,Long,Float,Double) V]\n(override final val data : Array[V], override final val offset : Int,\n override val stride : Int, override val length : Int)\n(implicit override val scalar : Scalar[V])\nextends DenseVector[V] with mutable.VectorRow[V] with mutable.VectorRowLike[V,DenseVectorRow[V]] {\n  def this(data : Array[V])(implicit s : Scalar[V]) =\n    this(data, 0, 1, data.length)(s);\n\n  // we have this pointless override to encourage hotspot to inline\n  @inline override def apply(key: Int) = data(offset + key * stride);\n\n  def apply(range : Range) : DenseVectorRow[V] = {\n    if(range.isEmpty) DenseVectorRow.zeros[V](0)\n    else {\n      require(range.last < length, \"Range out of bounds\");\n      new DenseVectorRow[V](data,\n        offset = offset + stride * range.start,\n        stride = stride * range.step,\n        length = range.size);\n    }\n  }\n\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) = {\n    implicit val mf = implicitly[Scalar[V2]].manifest;\n    domain match {\n      case that : IndexDomain => new DenseVectorRow(new Array[V2](that.size)).asBuilder;\n      case _ => super.newBuilder[K2,V2](domain);\n    }\n  }\n\n  override def t : DenseVectorCol[V] =\n    new DenseVectorCol(data, offset, stride, length)(scalar);\n\n  // Override asRow to avoid unnecessary copies.\n  @inline override def asRow: DenseVectorRow[V] = this\n}\n\n/**\n * DenseVector as a column.\n *\n * @author dramage\n */\nfinal class DenseVectorCol[@specialized(Int,Long,Float,Double) V]\n(override val data : Array[V], override val offset : Int,\n override val stride : Int, override val length : Int)\n(implicit override val scalar : Scalar[V])\nextends DenseVector[V] with mutable.VectorCol[V] with mutable.VectorColLike[V,DenseVectorCol[V]] with Serializable {\n  def this(data : Array[V])(implicit s : Scalar[V]) =\n    this(data, 0, 1, data.length)(s);\n\n  // we have this pointless override to encourage hotspot to inline\n  @inline override def apply(key: Int) = data(offset + key * stride);\n\n  def apply(range : Range) : DenseVectorCol[V] = {\n    if(range.isEmpty) DenseVectorCol.zeros[V](0)\n    else {\n      require(range.last < length, \"Range out of bounds\");\n      new DenseVectorCol[V](data,\n        offset = offset + stride * range.start,\n        stride = stride * range.step,\n        length = range.size);\n    }\n  }\n\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) = {\n    implicit val mf = implicitly[Scalar[V2]].manifest;\n    domain match {\n      case that : IndexDomain => new DenseVectorCol(new Array[V2](that.size)).asBuilder;\n      case _ => super.newBuilder[K2,V2](domain);\n    }\n  }\n\n  override def t : DenseVectorRow[V] =\n    new DenseVectorRow(data, offset, stride, length)(scalar);\n\n  // Override asCol to avoid unnecessary copies.\n  @inline override def asCol: DenseVectorCol[V] = this\n}\n\n/**\n * Common constructors shared by DenseVectorRow and DenseVectorCol.\n * @author dramage, afwlehmann\n *\n */\ntrait CommonDenseVectorConstructors [+This[_] <: DenseVector[_]] {\n  /**\n   * Constructs a DenseVector from the given values.\n   */\n  def apply[@specialized V: Scalar](values: Array[V]): This[V]\n\n  /**\n   * Constructs a DenseVector from the given values.\n   */\n  def apply[@specialized V: Scalar](values: V*): This[V] = {\n    implicit val mf = implicitly[Scalar[V]].manifest\n    apply(values.toArray)\n  }\n\n  /**\n   * Constructs a DenseVector for the given IndexDomain.\n   */\n  def apply[@specialized V: Scalar](domain: IndexDomain): This[V] =\n    zeros(domain.size)\n\n  /**\n   * Dense vector containing the given value for all elements.\n   */\n  def fill[V: Scalar](size: Int)(value: V): This[V] = {\n    implicit val mf = implicitly[Scalar[V]].manifest\n    // this is too slow: apply(Array.fill(size)(value))\n    if(mf.getClass.isAssignableFrom(java.lang.Double.TYPE)) {\n      val arr = new Array[V](size)\n      Arrays.fill(arr.asInstanceOf[Array[Double]],value.asInstanceOf[Double])\n      apply(arr)\n    } else if(mf.getClass.isAssignableFrom(java.lang.Float.TYPE)) {\n      val arr = new Array[V](size)\n      Arrays.fill(arr.asInstanceOf[Array[Float]],value.asInstanceOf[Float])\n      apply(arr)\n    } else if(mf.getClass.isAssignableFrom(java.lang.Integer.TYPE)) {\n      val arr = new Array[V](size)\n      Arrays.fill(arr.asInstanceOf[Array[Int]],value.asInstanceOf[Int])\n      apply(arr)\n    } else if(mf.getClass.isAssignableFrom(java.lang.Long.TYPE)) {\n      val arr = new Array[V](size)\n      Arrays.fill(arr.asInstanceOf[Array[Long]],value.asInstanceOf[Long])\n      apply(arr)\n    } else {\n      apply(Array.fill(size)(value))\n    }\n  }\n\n  /**\n   * DenseVector of zeros of the given size.\n   */\n  def zeros[V](size: Int)(implicit s: Scalar[V]): This[V] = {\n    if (s.isPrimitive)\n      apply(s.manifest.newArray(size))\n    else\n      fill(size)(s.zero)\n  }\n\n  /**\n   * DenseVector of ones of the given size.\n   */\n  def ones[V: Scalar](size: Int): This[V] =\n    fill(size)(implicitly[Scalar[V]].one)\n\n  /**\n   * Tabulate a DenseVector with the value at each offset given by the function.\n   */\n  def tabulate[V: Scalar](size: Int)(f: (Int => V)): This[V] = {\n    implicit val mf = implicitly[Scalar[V]].manifest\n    apply(Array.tabulate(size)(f))\n  }\n\n  /**\n   * Returns a vector with numbers from 'from' up to (but not including)\n   * 'until' incrementing by 'by' at each step.\n   */\n  def range(from: Int, until: Int, by: Int = 1): This[Int] =\n    apply[Int](Array.range(from, until, by))\n\n  /**\n   * A vector of the given size with uniform random values from [0,1).\n   */\n  def rand(size: Int, mt: MersenneTwisterFast = Random.mt): This[Double] =\n    mt.synchronized {\n      tabulate(size)(i => mt.nextDouble)\n    }\n\n  /**\n   * A vector of the given size with normally distributed random values\n   * with mean 0 and standard deviation 1.\n   */\n  def randn(size: Int, mt: MersenneTwisterFast = Random.mt): This[Double] =\n    mt.synchronized {\n      tabulate(size)(i => mt.nextGaussian)\n    }\n\n  /**\n   * A vector of the given size of random integers in the range [0..max).\n   */\n  def randi(imax: Int, size: Int, mt: MersenneTwisterFast = Random.mt): This[Int] =\n    mt.synchronized {\n      tabulate(size)(i => mt.nextInt(imax))\n    }\n}\n\n/**\n * @author dramage, afwlehmann\n */\nobject DenseVectorRow extends CommonDenseVectorConstructors[DenseVectorRow] {\n  /**\n   * {@inheritDoc}\n   */\n  override def apply[@specialized V: Scalar](values: Array[V]): DenseVectorRow[V] =\n    new DenseVectorRow[V](values)\n\n  /**\n   * Horizontal concatenation of two or more row vectors into one large vector.\n   */\n  def horzcat[V: Scalar](vectors: VectorRow[V]*): DenseVectorRow[V] = {\n    val size = vectors.foldLeft(0)(_ + _.size)\n    val result = zeros[V](size)\n    var offset = 0\n    for (v <- vectors) {\n      result(offset until (offset + v.size)) := v\n      offset += v.size\n    }\n    result\n  }\n\n  /**\n   * Vertical concatenation of two or more row vectors into one matrix.\n   * @throws IllegalArgumentException if vectors have different sizes\n   */\n  def vertcat[V: Scalar](vectors: VectorRow[V]*): DenseMatrix[V] = {\n    val size = vectors.head.size\n    if (!(vectors forall (_.size == size)))\n      throw new IllegalArgumentException(\"All vectors must have the same size!\")\n    val result = DenseMatrix.zeros[V](vectors.size, size)\n    for ((v, row) <- vectors zip (0 until vectors.size))\n      result(row,::) := v\n    result\n  }\n}\n\n/**\n * @author dramage, afwlehmann\n */\ntrait DenseVectorColConstructors extends CommonDenseVectorConstructors[DenseVectorCol] {\n  /**\n   * {@inheritDoc}\n   */\n  override def apply[@specialized V: Scalar](values: Array[V]): DenseVectorCol[V] =\n    new DenseVectorCol[V](values)\n\n  /**\n   * Horizontal concatenation of two or more row vectors into one matrix.\n   * @throws IllegalArgumentException if vectors have different sizes\n   */\n  def horzcat[V: Scalar](vectors: VectorCol[V]*): DenseMatrix[V] = {\n    val size = vectors.head.size\n    if (!(vectors forall (_.size == size)))\n      throw new IllegalArgumentException(\"All vectors must have the same size!\")\n    val result = DenseMatrix.zeros[V](vectors.size, size)\n    for ((v, col) <- vectors zip (0 until vectors.size))\n      result(::,col) := v\n    result\n  }\n\n  /**\n   * Vertical concatenation of two or more column vectors into one large vector.\n   */\n  def vertcat[V: Scalar](vectors: VectorCol[V]*): DenseVectorCol[V] = {\n    val size = vectors.foldLeft(0)(_ + _.size)\n    val result = zeros[V](size)\n    var offset = 0\n    for (v <- vectors) {\n      result(offset until (offset + v.size)) := v\n      offset += v.size\n    }\n    result\n  }\n}\n\nobject DenseVectorCol extends DenseVectorColConstructors\n\ntrait DenseVectorConstructors extends DenseVectorColConstructors\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/CanBuildDomain2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * Marker trait for statically building a Domain2 for two input domains.\n *\n * @author dramage\n */\ntrait CanBuildDomain2[-A,-B,RV] extends ((A,B) => RV);\n\ntrait CanBuildDomain2ImplicitsLevel0 {\n  implicit def buildGeneral[K1,K2]\n  : CanBuildDomain2[Domain1[K1],Domain1[K2],Domain2[K1,K2]]\n  = new CanBuildDomain2[Domain1[K1],Domain1[K2],Domain2[K1,K2]] {\n    def apply(a : Domain1[K1], b : Domain1[K2]) =\n      a.product[K2,Domain1[K2]](b);\n  }\n}\n\ntrait CanBuildDomain2ImplicitsLevel1 extends CanBuildDomain2ImplicitsLevel0 {\n  implicit object BuildIndexIndex \n  extends CanBuildDomain2[IndexDomain,IndexDomain,TableDomain] {\n    override def apply(a : IndexDomain, b : IndexDomain) =\n      TableDomain(a.size, b.size);\n  }\n}\n\nobject CanBuildDomain2 extends CanBuildDomain2ImplicitsLevel1;\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/CanGetDomain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * Marker trait for statically getting the domain of a given tensor.\n *\n * @author dramage\n */\ntrait CanGetDomain[-From,Domain] extends (From => Domain);\n\ntrait CanGetDomainImplicitsLevel0 {\n  implicit def domainForTensor[K,T](implicit view : T => Tensor[K,_])\n  : CanGetDomain[T,IterableDomain[K]]\n  = new CanGetDomain[T,IterableDomain[K]] { def apply(t : T) = t.domain; }\n}\n\ntrait CanGetDomainImplicitsLevel1 extends CanGetDomainImplicitsLevel0 {\n  implicit def domainForTensor1[K,T](implicit view : T => Tensor1[K,_])\n  : CanGetDomain[T,Domain1[K]]\n  = new CanGetDomain[T,Domain1[K]] { def apply(t : T) = t.domain; }\n\n  implicit def domainForTensor2[K1,K2,T](implicit view : T => Tensor2[K1,K2,_])\n  : CanGetDomain[T,Domain2[K1,K2]]\n  = new CanGetDomain[T,Domain2[K1,K2]] { def apply(t : T) = t.domain; }\n}\n\ntrait CanGetDomainImplicitsLevel2 extends CanGetDomainImplicitsLevel1 {\n  implicit def domainForVector[T](implicit view : T => Vector[_])\n  : CanGetDomain[T,IndexDomain]\n  = new CanGetDomain[T,IndexDomain] { def apply(t : T) = t.domain; }\n  \n  implicit def domainForMatrix[T](implicit view : T => Matrix[_])\n  = new CanGetDomain[T,TableDomain] { def apply(t : T) = t.domain; }\n}\n\nobject CanGetDomain extends CanGetDomainImplicitsLevel2 {\n  def apply[T] = new {\n    def apply[D](implicit df : CanGetDomain[T,D]) = df;\n  }\n}\n\n/**\n * Capability trait for statically getting the domain2 of a Tensor2.\n *\n * @author dramage\n */\ntrait CanGetDomain2[-From,D1,D2,Domain] extends (From => Domain) {\n  def _1(from : From) : D1;\n  def _2(from : From) : D2;\n}\n\ntrait CanGetDomain2ImplicitsLevel0 {\n  implicit def domainForTensor2[K1,K2,T](implicit view : T => Tensor2[K1,K2,_])\n  : CanGetDomain2[T,Domain1[K1],Domain1[K2],Domain2[K1,K2]]\n  = new CanGetDomain2[T,Domain1[K1],Domain1[K2],Domain2[K1,K2]] {\n    def apply(t : T) = t.domain;\n    def _1(t : T) = t.domain._1;\n    def _2(t : T) = t.domain._2;\n  }\n}\n\ntrait CanGetDomain2ImplicitsLevel1 extends CanGetDomain2ImplicitsLevel0 {\n  implicit def domainForMatrix[T](implicit view : T => Matrix[_])\n  : CanGetDomain2[T,IndexDomain,IndexDomain,TableDomain]\n  = new CanGetDomain2[T,IndexDomain,IndexDomain,TableDomain] {\n    def apply(t : T) = t.domain;\n    def _1(t : T) = t.domain._1;\n    def _2(t : T) = t.domain._2;\n  }\n}\n\nobject CanGetDomain2 extends CanGetDomain2ImplicitsLevel1 {\n  def apply[T] = new {\n    def apply[D1,D2,D](implicit df : CanGetDomain2[T,D1,D2,D]) = df;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/Domain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * Implementation trait for domains of a DomainFunction, representing\n * a restriction on values of type A.\n *\n * @author dramage\n */\ntrait DomainLike[@specialized(Int,Long,Float,Double) A, +This<:Domain[A]]\nextends (A => Boolean) {\n\n  def repr : This =\n    this.asInstanceOf[This];\n\n  /** Calls contains(key). */\n  final override def apply(key : A) = contains(key);\n\n  /** Returns true if the given element is part of the set. */\n  def contains(key : A) : Boolean;\n}\n\n/**\n * Domains of a DomainFunction, representing a restriction on values of type A.\n *\n * @author dramage\n */\ntrait Domain[@specialized(Int,Long,Float,Double) A]\nextends DomainLike[A, Domain[A]];\n\n/**\n * An exception thrown when encountering an invalid domain.\n *\n * @author dramage\n */\nclass DomainException(msg : String) extends RuntimeException(msg) {\n  def this() = this(null);\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/Domain1.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * A domain that explicitly has only one element, i.e. A is not a tuple.\n *\n * @author dramage\n */\ntrait Domain1Like[@specialized(Int,Long) A, +This<:Domain1[A]]\nextends IterableDomainLike[A,This] { outer =>\n  override def repr: This = this.asInstanceOf[This];\n\n  /** Constructs the union of this and the other domain. */\n  override def union(that : IterableDomain[A]) : IterableDomain[A] = that match {\n    case d1 : Domain1[_] => this.union(d1.asInstanceOf[Domain1[A]]);\n    case _ => super.union(that);\n  }\n\n  /** Constructs the union of this and the other domain. */\n  def union(that : Domain1[A]) : Domain1[A] = {\n    new Domain1[A] with UnionDomainLike[A,Domain1[A]] {\n      override def a = outer.repr;\n      override def b = that;\n    }\n  }\n\n  def product[B,That<:Domain1[B]](that : That) =\n    Domain2(repr,that);\n}\n\n/**\n * A domain that explicitly has only one element, i.e. A is not a tuple.\n *\n * @author dramage\n */\ntrait Domain1[@specialized(Int,Long) A]\nextends IterableDomain[A] with Domain1Like[A,Domain1[A]];\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/Domain2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * Implementation trait for a domain containing all pairs from\n * two underlying domains.\n *\n * @author dramage\n */\ntrait Domain2Like\n[@specialized(Int,Long) A1, @specialized(Int,Long) A2,\n +D1 <: Domain1[A1] with Domain1Like[A1,D1],\n +D2 <: Domain1[A2] with Domain1Like[A2,D2],\n +Transpose <: Domain2Like[A2,A1,D2,D1,This,Transpose],\n +This <: Domain2Like[A1,A2,D1,D2,Transpose,This]]\nextends IterableDomain[(A1,A2)] with DomainLike[(A1,A2),This] {\n  /** Row-space domain. */\n  def _1 : D1;\n\n  /** Col-space domain. */\n  def _2 : D2;\n\n  /** Constructs the union of this and the other domain. */\n  override def union(that : IterableDomain[(A1,A2)]) : IterableDomain[(A1,A2)] = that match {\n    case d1 : Domain2[_,_] => {\n      val casted = d1.asInstanceOf[Domain2[A1,A2]];\n      Domain2(this._1 union casted._1, this._2 union casted._2);\n    }\n    case _ => super.union(that);\n  }\n\n  /** Returns the transpose of this domain. */\n  def transpose : Transpose;\n\n  override def foreach[O](fn : ((A1,A2)) => O) =\n    for (k1 <- _1.iterator; k2 <- _2.iterator) fn((k1,k2));\n\n  /** Iterators all elements of this domain. */\n  override def iterator =\n    for (k1 <- _1.iterator; k2 <- _2.iterator) yield (k1,k2);\n\n  /** Returns true if a1 is in the row space and a2 is in the col space. */\n  def contains(a1 : A1, a2 : A2) =\n    _1.contains(a1) && _2.contains(a2);\n\n  /** Defers to contains(tup._1, tup._2). */\n  final override def contains(tup : (A1,A2)) =\n    contains(tup._1, tup._2);\n\n  override def equals(other : Any) = other match {\n    case that : Domain2[_,_] =>\n      this._1 == that._1 && this._2 == that._2;\n    case _ => super.equals(other);\n  }\n}\n\n/**\n * All pairs of elements from D1 and D2, both iterable domains.\n *\n * @author dramage\n */\ntrait Domain2\n[@specialized(Int,Long) A1, @specialized(Int,Long) A2]\nextends Product2[Domain1[A1],Domain1[A2]] with IterableDomain[(A1,A2)]\nwith Domain2Like[A1,A2,Domain1[A1],Domain1[A2],Domain2[A2,A1],Domain2[A1,A2]] {\n\n  def transpose =\n    Domain2[A2,A1](_2,_1);\n\n  override def size =\n    _1.size * _2.size;\n\n  override def canEqual(that : Any) =\n    that.isInstanceOf[Domain2[_,_]];\n\n  override def toString =\n    \"Domain2(\"+_1.toString+\",\"+_2.toString+\")\";\n}\n\nobject Domain2 {\n  def apply[A1,A2](d1 : Domain1[A1], d2 : Domain1[A2])\n  : Domain2[A1,A2] = new Impl(d1,d2);\n\n  class Impl[@specialized(Int,Long) A1, @specialized(Int,Long) A2]\n  (override val _1 : Domain1[A1], override val _2 : Domain1[A2])\n  extends Domain2[A1,A2];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/DomainN.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * A domain indexed by sequences of underyling key type K.\n *\n * @author dramage\n */\ncase class DomainN[@specialized(Int) K](components : Seq[IterableDomain[K]])\nextends IterableDomain[Seq[K]] with IterableDomainLike[Seq[K],DomainN[K]] {\n\n  override def size =\n    components.map(_.size).reduceLeft(_ * _);\n\n  override def union(other : IterableDomain[Seq[K]]) = other match {\n    case that : DomainN[_] => {\n      val casted = that.asInstanceOf[DomainN[K]];\n      require(this.components.size == casted.components.size, \"Can only take the union of product domains of the same size\");\n      DomainN((this.components zip casted.components) map (tup => tup._1 union tup._2));\n    }\n    case _ => super.union(other);\n  }\n\n  override def foreach[O](fn : (Seq[K] => O)) = {\n    def unroll(key : List[K], remaining : Seq[IterableDomain[K]]) {\n      require(remaining.length > 0);\n      if (remaining.length == 1) {\n        remaining.head.foreach(e => fn(key :+ e));\n      } else {\n        remaining.head.foreach(e => unroll(key :+ e, remaining.tail));\n      }\n    }\n    unroll(List.empty[K], components);\n  }\n\n  /** Iterators all elements of this domain. */\n  override def iterator = {\n    def unroll(remaining : Seq[IterableDomain[K]]) : Iterator[Seq[K]] = {\n      require(remaining.length > 0);\n      if (remaining.length == 1) {\n        remaining.head.iterator.map(k => List(k));\n      } else {\n        for (k <- remaining.head.iterator;\n             rest <- unroll(remaining.tail))\n        yield List(k) ++ rest;\n      }\n    }\n\n    unroll(components);\n  }\n\n  /** Returns true if a1 is in the row space and a2 is in the col space. */\n  def contains(k : Seq[K]) =\n    (components.length == k.length) && (components zip k).forall(tup => tup._1 contains tup._2);\n\n  override def equals(other : Any) = other match {\n    case that : DomainN[_] =>\n      this.components == that.components\n    case base : Domain[_] =>\n      super.equals(base);\n    case _ => false;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/IndexDomain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * The domain of indices: ints starting from 0 up to a bounded size.\n *\n * @author dramage\n */\ncase class IndexDomain(override val size : Int)\nextends Domain1[Int] with Domain1Like[Int,IndexDomain] {\n  override def foreach[O](fn : Int=>O) = {\n    var i = 0;\n    while (i < size) {\n      fn(i);\n      i += 1;\n    }\n  }\n\n  override def product[B,That<:Domain1[B]](that : That) = that match {\n    case IndexDomain(otherSize) => TableDomain(size,otherSize);\n    case _ => super.product[B,That](that);\n  }\n\n  override def toIndexedSeq[B>:Int] =\n    Range(0,size);\n    \n  override def contains(key : Int) =\n    key >= 0 && key < size;\n\n  override def union(other : IterableDomain[Int]) = other match {\n    case that : IndexDomain => IndexDomain(this.size max that.size);\n    case _ => super.union(other);\n  }\n\n  override def iterator =\n    Iterator.range(0, size);\n\n  override def toString =\n    \"IndexDomain(\"+size+\")\";\n    \n  override def equals(other : Any) = other match {\n    case IndexDomain(s) => this.size == s;\n    case _ => super.equals(other);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/IterableDomain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * Implementation trait for a domain that can be traversed.  Default\n * equality check returns true if this eq other or if this and other\n * traverse the same elements in the same order.\n *\n * @author dramage\n */\ntrait IterableDomainLike[@specialized(Int,Long) A, +This<:IterableDomain[A]]\nextends DomainLike[A,This] with Iterable[A] { outer =>\n  override def repr: This = this.asInstanceOf[This];\n  /** Applies the given function to every element of the domain. */\n  def foreach[O](f : A => O);\n\n  /** Iterates over the elements of the domain. */\n  def iterator : Iterator[A];\n\n  /** Constructs the union of this and the other domain. */\n  def union(that : IterableDomain[A]) : IterableDomain[A] = {\n    new IterableDomain[A] with UnionDomainLike[A,IterableDomain[A]] {\n      override def a = outer.repr;\n      override def b = that;\n    }\n  }\n\n  /** Number of elements in the domain. */\n  def size : Int;\n\n//  def toIndexedSeq =\n//    iterator.toIndexedSeq;\n\n//  def toArray(implicit mf : Manifest[A]) =\n//    iterator.toArray;\n\n//  def filter(fn : A => Boolean) : List[A] =\n//    iterator.filter(fn).toList;\n\n//  def max(implicit ord : Ordering[A]) =\n//    iterator.max(ord);\n\n//  def min(implicit ord : Ordering[A]) =\n//    iterator.min(ord);\n\n  override def equals(other : Any) = other match {\n    case that : IterableDomain[_] =>\n      (this eq that) || (this.iterator zip that.iterator).forall(tup => tup._1 == tup._2);\n    case _ =>\n      false;\n  }\n}\n\n/**\n * A domain that can be traversed.\n *\n * @author dramage\n */\ntrait IterableDomain[@specialized(Int,Long) A]\nextends Domain[A] with IterableDomainLike[A,IterableDomain[A]];\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/SetDomain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * The domain of elements from a specific set.\n *\n * @author dramage\n */\ncase class SetDomain[@specialized(Int,Long) A](set : scala.collection.Set[A])\nextends Domain1[A] with Domain1Like[A,SetDomain[A]] {\n\n  override def size =\n    set.size;\n\n  override def foreach[O](fn : A=>O) =\n    set.foreach(fn);\n\n  override def iterator =\n    set.iterator;\n\n  override def contains(key : A) : Boolean =\n    set.contains(key);\n\n  override def equals(other : Any) = other match {\n    case SetDomain(s) => this.set == s;\n    case that : Domain[_] => super.equals(that);\n    case _ => false;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/TableDomain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * An immutable Domain2 indexed by rows and columns.\n *\n * @author dramage\n */\ncase class TableDomain(numRows : Int, numCols : Int)\nextends Product2[IndexDomain,IndexDomain] with Domain2[Int,Int]\nwith Domain2Like[Int,Int,IndexDomain,IndexDomain,TableDomain,TableDomain] {\n\n  override val _1 : IndexDomain = IndexDomain(numRows);\n  \n  override val _2 : IndexDomain = IndexDomain(numCols);\n\n  override def transpose =\n    TableDomain(numCols, numRows);\n\n  override def foreach[O](fn : (((Int,Int))=>O)) = {\n    var i = 0;\n    while (i < numRows) {\n      var j = 0;\n      while (j < numCols) {\n        fn((i,j));\n        j += 1;\n      }\n      i += 1;\n    }\n  }\n\n  override def union(other : IterableDomain[(Int,Int)]) : IterableDomain[(Int,Int)] = other match {\n    case that : TableDomain =>\n      TableDomain(this.numRows max that.numRows, this.numCols max that.numCols);\n    case _ => super.union(other);\n  }\n\n  override def toString =\n    \"TableDomain(\"+numRows+\",\"+numCols+\")\";\n\n  override def equals(other : Any) = other match {\n    case TableDomain(nr,nc) => this.numRows == nr && this.numCols == nc;\n    case _ => super.equals(other);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/UnionDomain.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage domain;\n\n/**\n * Trait that represents the union of two domains.\n *\n * @author dramage\n */\ntrait UnionDomainLike[@specialized(Int,Long) A, +This<:IterableDomain[A]]\nextends IterableDomainLike[A, This] {\n  def a : IterableDomain[A];\n  def b : IterableDomain[A];\n  \n  override def size = {\n    var s = 0;\n    foreach(k => { s += 1; })\n    s\n  }\n\n  override def foreach[O](fn : A=>O) = {\n    a.foreach(fn);\n    b.foreach(k => if (!a.contains(k)) fn(k));\n  }\n\n  override def iterator =\n    a.iterator ++ b.iterator.filterNot(a.contains);\n\n  override def contains(key : A) : Boolean =\n    a.contains(key) || b.contains(key);\n\n  override def equals(other : Any) = other match {\n    case that : UnionDomainLike[_,_] => this.a == that.a && this.b == that.b;\n    case _ => super.equals(other);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorBuilder.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\n/**\n * Builds a Tensor of type To after being given a series of\n * key, value pairs.\n *\n * @author dramage\n */\ntrait TensorBuilder[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,+To] {\n  def update(key : K, value : V);\n\n  def result : To;\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorKeysMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._;\n\n/**\n * Support for comprehensions on keys from an underlying tensor.  This\n * class can be implicitly viewed as an Iterable[K].\n *\n * @author dramage\n */\ntrait TensorKeysMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] {\n  \n  def repr : This;\n  \n  /** Calls repr.foreachKey. */\n  def foreach[U](fn : K => U) =\n    repr.foreachKey(fn);\n\n  /** Calls repr.size. */\n  def size =\n    repr.size;\n\n  /** Calls repr.keysIterator. */\n  def iterator =\n    repr.keysIterator;\n  \n  /** Constructs a filtered view of this tensor. */\n  def filter[D,That](p : K => Boolean) =\n    withFilter(p);\n  \n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : K => Boolean) =\n    new TensorKeysMonadic.Filtered[K,V,This](repr, p);\n}\n\nobject TensorKeysMonadic {\n  /** Filtered view of the keys in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V, +This<:Tensor[K,V]]\n  (val repr : This, p : K=>Boolean) {\n    def foreach[U](fn : K => U) =\n      repr.foreachKey(k => if (p(k)) fn(k));\n    \n    def withFilter(q : K => Boolean) =\n      new Filtered[K,V,This](repr, k => p(k) && q(k));\n    \n//    def map[U,D,That](fn : K => U)\n//    (implicit df : CanGetDomain[This,D], bf : CanBuildTensorFrom[This,D,K,U,That]) = {\n//      val builder = bf(repr, repr.domain.asInstanceOf[D]);\n//      repr.foreachPair((k,v) => if (p(k)) builder(k) = fn(k));\n//      builder.result;\n//    }\n//      \n//    def strict[D,That]\n//    (implicit df : CanGetDomain[This,D], bf : CanBuildTensorFrom[This,D,K,V,That]) = {\n//      val builder = bf(repr, repr.domain.asInstanceOf[D]);\n//      repr.foreachPair((k,v) => if (p(k)) builder(k) = v);\n//      builder.result;\n//    }\n  }\n  \n  implicit def asIterable[K, V, T<:Tensor[K,V]](values : TensorKeysMonadic[K,V,T]) = {\n    new Iterable[K] {\n      def self = values.repr;\n      override def foreach[U](fn : K => U) = self.foreachKey(fn);\n      override def iterator = self.keysIterator;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroKeysMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._;\n\n/**\n * Support for comprehensions on all non-zero-valued keys (and some zeros) from\n * an underlying tensor.  This class can be implicitly viewed as an Iterable[K].\n *\n * @author dramage\n */\ntrait TensorNonZeroKeysMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] {\n  \n  def repr : This;\n  \n  /** Calls repr.foreachKey. */\n  def foreach[U](fn : K => U) =\n    repr.foreachNonZeroKey(fn);\n\n  /** Calls repr.nonzeroSize. */\n  def size =\n    repr.nonzeroSize;\n\n  /** Calls repr.keysIterator. */\n  def iterator =\n    repr.keysIteratorNonZero;\n  \n  /** Constructs a filtered view of this tensor. */\n  def filter[D,That](p : K => Boolean) =\n    withFilter(p);\n  \n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : K => Boolean) =\n    new TensorNonZeroKeysMonadic.Filtered[K,V,This](repr, p);\n}\n\nobject TensorNonZeroKeysMonadic {\n  /** Filtered view of the keys in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V, +This<:Tensor[K,V]]\n  (val repr : This, p : K=>Boolean) {\n    def foreach[U](fn : K => U) =\n      repr.foreachNonZeroKey(k => if (p(k)) fn(k));\n    \n    def withFilter(q : K => Boolean) =\n      new Filtered[K,V,This](repr, k => p(k) && q(k));\n  }\n  \n  implicit def asIterable[K, V, T<:Tensor[K,V]](values : TensorNonZeroKeysMonadic[K,V,T]) = {\n    new Iterable[K] {\n      def self = values.repr;\n      override def foreach[U](fn : K => U) = self.foreachNonZeroKey(fn);\n      override def iterator = self.keysIteratorNonZero;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._\nimport operators.HasValuesMonadic\n;\n\n/**\n * For comprehensions on pairs of values from an underlying tensor.  This\n * class can be implicitly viewed as a Map[K,V].\n *\n * @author dramage\n */\ntrait TensorNonZeroMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] extends HasValuesMonadic[This,V] { self =>\n\n  /** Underlying tensor. */\n  def repr : This;\n\n  /** Calls repr.nonzeroSize. */\n  def size =\n    repr.nonzeroSize;\n    \n  /** Gets a Monadic for the nonzero pairs. */\n  def pairs : TensorNonZeroPairsMonadic[K,V,This] =\n    new TensorNonZeroPairsMonadic[K,V,This] { override def repr = self.repr };\n    \n  /** Gets a Monadic for the nonzero keys. */\n  def keys : TensorNonZeroKeysMonadic[K,V,This] =\n    new TensorNonZeroKeysMonadic[K,V,This] { override def repr = self.repr };\n  \n  /** Gets a Monadic for the nonzero values. */\n  def values : TensorNonZeroValuesMonadic[K,V,This] =\n    new TensorNonZeroValuesMonadic[K,V,This] { override def repr = self.repr };\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroPairsMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._;\n\n/**\n * For comprehensions on pairs of values from an underlying tensor.  This\n * class can be implicitly viewed as a Map[K,V].\n *\n * @author dramage\n */\ntrait TensorNonZeroPairsMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] { self =>\n\n  /** Underlying tensor. */\n  def repr : This;\n  \n  /** Calls repr.foreachPair. */\n  def foreach[U](fn : ((K,V)) => U) =\n    repr.foreachNonZeroPair((k,v) => fn((k,v)));\n\n  /** Calls repr.nonzeroSize. */\n  def size =\n    repr.nonzeroSize;\n  \n  /** Calls repr.mapPairs. */\n  def map[TT>:This,O,That](fn : ((K,V)) => O)\n  (implicit bf : CanMapKeyValuePairs[TT, K, V, O, That]) : That =\n    repr.mapNonZeroPairs((k,v) => fn((k,v)))(bf.asInstanceOf[CanMapKeyValuePairs[Tensor[K,V],K,V,O,That]]);\n\n  /** Calls repr.pairsIterator. */\n  def iterator =\n    repr.pairsIteratorNonZero;\n\n  /** Constructs a filtered view of this tensor. */\n  def filter(p : ((K,V)) => Boolean) =\n    withFilter(p);\n  \n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : ((K,V)) => Boolean) =\n    new TensorNonZeroPairsMonadic.Filtered[K,V,This](repr, p);\n}\n\nobject TensorNonZeroPairsMonadic {\n  /** Filtered view of the pairs in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V, +This<:Tensor[K,V]]\n  (val repr : This, p : ((K,V))=>Boolean) {\n    def foreach[U](fn : ((K,V)) => U) =\n      repr.foreachNonZeroPair((k,v) => if (p((k,v))) fn((k,v)));\n    \n    def withFilter(q : ((K,V)) => Boolean) =\n      new Filtered[K,V,This](repr, tup => p(tup) && q(tup));\n  }\n  \n  implicit def asMap[K,V,T<:Tensor[K,V]](pairs : TensorNonZeroPairsMonadic[K,V,T]) = {\n    new scala.collection.Map[K,V] {\n      def self = pairs.repr;\n      override def foreach[U](fn : ((K,V)) => U) = pairs.foreach(fn);\n      override def keysIterator = self.keysIteratorNonZero;\n      override def valuesIterator = self.valuesIteratorNonZero;\n      override def contains(key : K) = self.isDefinedAt(key);\n      override def apply(key : K) = self.apply(key);\n      override def iterator = self.pairsIteratorNonZero;\n      override def get(key : K) =\n        if (self.isDefinedAt(key)) Some(self.apply(key)) else None;\n      override def - (key : K) =\n        this.toMap.-(key);\n      override def + [V1>:V](kv : (K,V1)): scala.collection.Map[K,V1] =\n        this.toMap.+(kv);\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroTriplesMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._\nimport scala.collection.generic.CanBuildFrom\nimport operators.HasValuesMonadic\n\n/**\n * For comprehensions on nonzero triples of values from an underlying 2-axis tensor.\n * This class can be implicitly viewed as an Iterable[(K1,K2,V)].\n *\n * @author dramage\n */\ntrait TensorNonZeroTriplesMonadic\n[@specialized(Int,Long) K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor2[K1,K2,V]] {\n\n  /** Underlying tensor. */\n  def repr : This;\n  \n  /** Calls repr.foreachTriple. */\n  def foreach[U](fn : ((K1,K2,V)) => U) =\n    repr.foreachNonZeroTriple((k1,k2,v) => fn((k1,k2,v)));\n\n  /** Calls repr.size. */\n  def size =\n    repr.size;\n  \n  /** Calls repr.mapTriples. */\n  def map[TT>:This,O,That](fn : ((K1,K2,V)) => O)\n  (implicit bf : CanMapKeyValuePairs[TT, (K1,K2), V, O, That]) : That =\n    repr.mapNonZeroTriples((k1,k2,v) => fn((k1,k2,v)))(bf.asInstanceOf[CanMapKeyValuePairs[Tensor2[K1,K2,V],(K1,K2),V,O,That]]);\n\n  /** Calls repr.TriplesIterator. */\n  def iterator =\n    repr.triplesIteratorNonZero;\n\n  /** Constructs a filtered view of this tensor. */\n  def filter(p : ((K1,K2,V)) => Boolean) =\n    withFilter(p);\n  \n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : ((K1,K2,V)) => Boolean) =\n    new TensorNonZeroTriplesMonadic.Filtered[K1,K2,V,This](repr, p);\n}\n\nobject TensorNonZeroTriplesMonadic {\n  /** Filtered view of the Triples in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V, +This<:Tensor2[K1,K2,V]]\n  (val repr : This, p : ((K1,K2,V))=>Boolean) {\n    def foreach[U](fn : ((K1,K2,V)) => U) =\n      repr.foreachNonZeroTriple((k1,k2,v) => if (p((k1,k2,v))) fn((k1,k2,v)));\n    \n    def withFilter(q : ((K1,K2,V)) => Boolean) =\n      new Filtered[K1,K2,V,This](repr, tup => p(tup) && q(tup));\n\n     /** Calls repr.mapTriples. */\n    def map[O,That](fn : ((K1,K2,V)) => O)\n    (implicit bf : CanBuildFrom[Iterable[(K1,K2,V)],O,That]) : That = {\n      val b = bf();\n      repr.foreachNonZeroTriple((k1,k2,v) => if(p((k1,k2,v))) b += fn((k1,k2,v)));\n      b.result;\n    }\n  }\n  \n  implicit def asIterable[K1, K2, V, T<:Tensor2[K1,K2,V]](values : TensorTriplesMonadic[K1,K2,V,T]) = {\n    new Iterable[(K1,K2,V)] {\n      def self = values.repr;\n      override def foreach[U](fn : ((K1,K2,V)) => U) =\n        self.foreachNonZeroTriple((i,j,v) => fn((i,j,v)));\n      override def iterator = self.triplesIteratorNonZero;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroValuesMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._\nimport operators.ValuesMonadic\n\n/**\n * Support for comprehensions on values from an underlying tensor.  This\n * class can be implicitly viewed as an Iterable[V].\n *\n * @author dramage\n */\ntrait TensorNonZeroValuesMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] extends ValuesMonadic[This,V] {\n  /** Underlying tensor. */\n  def repr : This;\n\n  /** Calls repr.foreachValue. */\n  def foreach[U](fn : V => U) =\n    repr.foreachNonZeroValue(fn);\n\n  /** Calls repr.nonzeroSize. */\n  def size =\n    repr.nonzeroSize;\n\n  /** Calls repr.mapValues. */\n  override def map[TT>:This,O,That](fn : V => O)\n  (implicit bf : CanMapValues[TT, V, O, That]) : That =\n    repr.mapNonZeroValues(fn)(bf.asInstanceOf[CanMapValues[Tensor[K,V],V,O,That]]);\n\n  /** Calls repr.valuesIterator. */\n  def iterator =\n    repr.valuesIteratorNonZero;\n\n  /** Constructs a filtered view of this tensor. */\n  def filter[D,That](p : V => Boolean) =\n    withFilter(p);\n\n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : V => Boolean) =\n    new TensorNonZeroValuesMonadic.Filtered[K,V,This](repr, p);\n}\n\nobject TensorNonZeroValuesMonadic {\n  /** Filtered view of the values in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V, +This<:Tensor[K,V]]\n  (val repr : This, p : V=>Boolean) {\n    def foreach[U](fn : V => U) =\n      repr.foreachNonZeroValue(v => if (p(v)) fn(v));\n\n    def withFilter(q : V => Boolean) =\n      new Filtered[K,V,This](repr, v => p(v) && q(v));\n\n//    def map[U,D,That](fn : V => U)\n//    (implicit df : CanGetDomain[This,D], bf : CanBuildTensorFrom[This,D,K,U,That]) = {\n//      val builder = bf(repr, repr.domain.asInstanceOf[D]);\n//      repr.foreachPair((k,v) => if (p(v)) builder(k) = fn(v));\n//      builder.result;\n//    }\n//\n//    def strict[D,That]\n//    (implicit df : CanGetDomain[This,D], bf : CanBuildTensorFrom[This,D,K,V,That]) = {\n//      val builder = bf(repr, repr.domain.asInstanceOf[D]);\n//      repr.foreachPair((k,v) => if (p(v)) builder(k) = v);\n//      builder.result;\n//    }\n  }\n\n  implicit def asIterable[K, @specialized(Int,Long,Float,Double) V, T<:Tensor[K,V]]\n  (values : TensorNonZeroValuesMonadic[K,V,T]) = {\n    new Iterable[V] {\n      def self = values.repr;\n      override def foreach[U](fn : V => U) = self.foreachNonZeroValue(fn);\n      override def iterator = self.valuesIteratorNonZero;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorPairsMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._\nimport scala.collection.generic.CanBuildFrom\nimport operators.HasValuesMonadic\n\n/**\n * For comprehensions on pairs of values from an underlying tensor.  This\n * class can be implicitly viewed as a Map[K,V].\n *\n * @author dramage\n */\ntrait TensorPairsMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] {\n\n  /** Underlying tensor. */\n  def repr : This;\n  \n  /** Calls repr.foreachPair. */\n  def foreach[U](fn : ((K,V)) => U) =\n    repr.foreachPair((k,v) => fn((k,v)));\n\n  /** Calls repr.size. */\n  def size =\n    repr.size;\n  \n  /** Calls repr.mapPairs. */\n  def map[TT>:This,O,That](fn : ((K,V)) => O)\n  (implicit bf : CanMapKeyValuePairs[TT, K, V, O, That]) : That =\n    repr.mapPairs((k,v) => fn((k,v)))(bf.asInstanceOf[CanMapKeyValuePairs[Tensor[K,V],K,V,O,That]]);\n\n  /** Calls repr.pairsIterator. */\n  def iterator =\n    repr.pairsIterator;\n\n  /** Constructs a filtered view of this tensor. */\n  def filter(p : ((K,V)) => Boolean) =\n    withFilter(p);\n  \n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : ((K,V)) => Boolean) =\n    new TensorPairsMonadic.Filtered[K,V,This](repr, p);\n}\n\nobject TensorPairsMonadic {\n  /** Filtered view of the pairs in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V, +This<:Tensor[K,V]]\n  (val repr : This, p : ((K,V))=>Boolean) {\n    def foreach[U](fn : ((K,V)) => U) =\n      repr.foreachPair((k,v) => if (p((k,v))) fn((k,v)));\n    \n    def withFilter(q : ((K,V)) => Boolean) =\n      new Filtered[K,V,This](repr, tup => p(tup) && q(tup));\n\n     /** Calls repr.mapPairs. */\n    def map[O,That](fn : ((K,V)) => O)\n                   (implicit bf : CanBuildFrom[Iterable[(K,V)],O,That]) : That = {\n      val b = bf();\n      repr.foreachPair( (k,v) =>\n        if(p(k -> v)) b += fn(k->v)\n      )\n      b.result;\n    }\n  }\n  \n  implicit def asMap[K,V,T<:Tensor[K,V]](pairs : TensorPairsMonadic[K,V,T]) = {\n    new scala.collection.Map[K,V] {\n      def self = pairs.repr;\n      override def foreach[U](fn : ((K,V)) => U) = pairs.foreach(fn);\n      override def keysIterator = self.keysIterator;\n      override def valuesIterator = self.valuesIterator;\n      override def contains(key : K) = self.isDefinedAt(key);\n      override def apply(key : K) = self.apply(key);\n      override def iterator = self.pairsIterator;\n      override def get(key : K) =\n        if (self.isDefinedAt(key)) Some(self.apply(key)) else None;\n      override def - (key : K) =\n        this.toMap.-(key);\n      override def + [V1>:V](kv : (K,V1)): scala.collection.Map[K,V1] =\n        this.toMap.+(kv);\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorTriplesMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._\nimport scala.collection.generic.CanBuildFrom\nimport operators.HasValuesMonadic\n\n/**\n * For comprehensions on Triples of values from an underlying 2-axis tensor.\n * This class can be implicitly viewed as an Iterable[(K1,K2,V)].\n *\n * @author dramage\n */\ntrait TensorTriplesMonadic\n[@specialized(Int,Long) K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor2[K1,K2,V]] {\n\n  /** Underlying tensor. */\n  def repr : This;\n  \n  /** Calls repr.foreachTriple. */\n  def foreach[U](fn : ((K1,K2,V)) => U) =\n    repr.foreachTriple((k1,k2,v) => fn((k1,k2,v)));\n\n  /** Calls repr.size. */\n  def size =\n    repr.size;\n  \n  /** Calls repr.mapTriples. */\n  def map[TT>:This,O,That](fn : ((K1,K2,V)) => O)\n  (implicit bf : CanMapKeyValuePairs[TT, (K1,K2), V, O, That]) : That =\n    repr.mapTriples((k1,k2,v) => fn((k1,k2,v)))(bf.asInstanceOf[CanMapKeyValuePairs[Tensor2[K1,K2,V],(K1,K2),V,O,That]]);\n\n  /** Calls repr.TriplesIterator. */\n  def iterator =\n    repr.triplesIterator;\n\n  /** Constructs a filtered view of this tensor. */\n  def filter(p : ((K1,K2,V)) => Boolean) =\n    withFilter(p);\n  \n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : ((K1,K2,V)) => Boolean) =\n    new TensorTriplesMonadic.Filtered[K1,K2,V,This](repr, p);\n}\n\nobject TensorTriplesMonadic {\n  /** Filtered view of the Triples in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V, +This<:Tensor2[K1,K2,V]]\n  (val repr : This, p : ((K1,K2,V))=>Boolean) {\n    def foreach[U](fn : ((K1,K2,V)) => U) =\n      repr.foreachTriple((k1,k2,v) => if (p((k1,k2,v))) fn((k1,k2,v)));\n    \n    def withFilter(q : ((K1,K2,V)) => Boolean) =\n      new Filtered[K1,K2,V,This](repr, tup => p(tup) && q(tup));\n\n     /** Calls repr.mapTriples. */\n    def map[O,That](fn : ((K1,K2,V)) => O)\n    (implicit bf : CanBuildFrom[Iterable[(K1,K2,V)],O,That]) : That = {\n      val b = bf();\n      repr.foreachTriple((k1,k2,v) => if(p((k1,k2,v))) b += fn((k1,k2,v)));\n      b.result;\n    }\n  }\n  \n  implicit def asIterable[K1, K2, V, T<:Tensor2[K1,K2,V]](values : TensorTriplesMonadic[K1,K2,V,T]) = {\n    new Iterable[(K1,K2,V)] {\n      def self = values.repr;\n      override def foreach[U](fn : ((K1,K2,V)) => U) =\n        self.foreachTriple((i,j,v) => fn((i,j,v)));\n        \n      override def iterator = self.triplesIterator;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorValuesMonadic.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage generic;\n\nimport domain.CanGetDomain;\nimport scalala.generic.collection._\nimport operators.ValuesMonadic;\n\n/**\n * Support for comprehensions on values from an underlying tensor.  This\n * class can be implicitly viewed as an Iterable[V].\n *\n * @author dramage\n */\ntrait TensorValuesMonadic\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +This<:Tensor[K,V]] extends ValuesMonadic[This,V] {\n \n  /** Underlying tensor. */\n  def repr : This;\n\n  /** Calls repr.foreachValue. */\n  def foreach[U](fn : V => U) =\n    repr.foreachValue(fn);\n\n  /** Calls repr.size. */\n  def size =\n    repr.size;\n\n  /** Calls repr.mapValues. */\n  override def map[TT>:This,O,That](fn : V => O)\n  (implicit bf : CanMapValues[TT, V, O, That]) : That =\n    repr.mapValues(fn)(bf.asInstanceOf[CanMapValues[Tensor[K,V],V,O,That]]);\n\n  /** Calls repr.valuesIterator. */\n  def iterator =\n    repr.valuesIterator;\n\n  /** Constructs a filtered view of this tensor. */\n  def filter[D,That](p : V => Boolean) =\n    withFilter(p);\n\n  /** Constructs a filtered view of this tensor. */\n  def withFilter(p : V => Boolean) =\n    new TensorValuesMonadic.Filtered[K,V,This](repr, p);\n}\n\nobject TensorValuesMonadic {\n  /** Filtered view of the values in a Tensor.  Does not support map. */\n  class Filtered\n  [@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V, +This<:Tensor[K,V]]\n  (val repr : This, p : V=>Boolean) {\n    def foreach[U](fn : V => U) =\n      repr.foreachValue(v => if (p(v)) fn(v));\n\n    def withFilter(q : V => Boolean) =\n      new Filtered[K,V,This](repr, v => p(v) && q(v));\n\n//    def map[U,D,That](fn : V => U)\n//    (implicit df : CanGetDomain[This,D], bf : CanBuildTensorFrom[This,D,K,U,That]) = {\n//      val builder = bf(repr, repr.domain.asInstanceOf[D]);\n//      repr.foreachPair((k,v) => if (p(v)) builder(k) = fn(v));\n//      builder.result;\n//    }\n//\n//    def strict[D,That]\n//    (implicit df : CanGetDomain[This,D], bf : CanBuildTensorFrom[This,D,K,V,That]) = {\n//      val builder = bf(repr, repr.domain.asInstanceOf[D]);\n//      repr.foreachPair((k,v) => if (p(v)) builder(k) = v);\n//      builder.result;\n//    }\n  }\n\n  implicit def asIterable[K, @specialized(Int,Long,Float,Double) V, T<:Tensor[K,V]]\n  (values : TensorValuesMonadic[K,V,T]) = {\n    new Iterable[V] {\n      def self = values.repr;\n      override def foreach[U](fn : V => U) = self.foreachValue(fn);\n      override def iterator = self.valuesIterator;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/CRSTensor2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain._;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._\nimport tensor.Counter2.Curried\nimport scala.collection.mutable.HashMap\n;\n\n\n/**\n * A mutable Tensor2 with an open row key domain that maps to an arbitrary Tensor1 as its rows.\n *\n * CRS = Compress Row Storage\n *\n * @author dlwh\n */\ntrait CRSTensor2Like\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V,\n +M1[VV]<:Curried[scala.collection.mutable.Map,K1]#Result[VV],\n +T<:scalala.tensor.mutable.Tensor1[K2,V],\n +This<:CRSTensor2[K1,K2,V,T]]\nextends tensor.CRSTensor2Like[K1,K2,V,M1,T,This] with Tensor2Like[K1,K2,V,SetDomain[K1], SetDomain[K2], Domain2[K1,K2], Domain2[K2,K1], This] { self =>\n\n  def update(k1 : K1, k2: K2, v : V) =\n    innerGetOrElseUpdate(k1,data)(k2) = v;\n\n  private[mutable] def innerGetOrElseUpdate[M](k:K1, m: scala.collection.mutable.Map[K1,M]): M = {\n    m.getOrElseUpdate(k,m.default(k))\n  }\n}\n\ntrait CRSTensor2\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V, +T<:Tensor1[K2,V]]\nextends tensor.CRSTensor2[K1,K2,V,T] with Tensor2[K1,K2,V]\nwith CRSTensor2Like[K1,K2, V,Curried[scala.collection.mutable.Map,K1]#Result,T,CRSTensor2[K1,K2,V,T]];\n\nobject CRSTensor2 {\n  class Impl[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V, T<:Tensor1[K2,V]]\n  (override val data : scala.collection.mutable.Map[K1,T],\n   override val k2domain: Domain1[K2])\n  (implicit override val scalar : Scalar[V], zeros: CanCreateZerosLike[T,T])\n  extends CRSTensor2[K1,K2,V,T];\n\n  /**\n   * Returns a new empty CRSTensor2 using the \"template\" to create rows. The actual rows are zero'd out versions of\n   * the template.\n   */\n  def apply[K1,K2,V,T<:Tensor1[K2,V]](template: T)(implicit view: CanViewAsTensor1[T,K2,V],\n                                                   zeros: CanCreateZerosLike[T,T],\n                                                   scalar: Scalar[V]) : mutable.CRSTensor2[K1,K2,V,T] = {\n    val map = new HashMap[K1,T] {\n      override def default(k: K1) = zeros(template);\n    }\n    new Impl[K1,K2,V,T](map, template.domain);\n  }\n\n  implicit def canSliceRow[K1,K2,V,T<:Tensor1[K2,V]]\n  : CanSliceRow[CRSTensor2[K1,K2,V,T],K1,T]\n  = new CanSliceRow[CRSTensor2[K1,K2,V,T],K1,T] {\n    override def apply(from : CRSTensor2[K1,K2,V,T], row : K1) = from.innerGetOrElseUpdate(row,from.data);\n  }\n\n\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Counter.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain._;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\n\n/**\n * A mutable tensor that acts like a collection of key-value pairs backed by\n * a map.\n *\n * @author dramage\n */\ntrait CounterLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +M<:scala.collection.mutable.Map[K,V],\n +This<:Counter[K,V]]\nextends tensor.CounterLike[K,V,M,This] with Tensor1Like[K,V,SetDomain[K],This] { self =>\n\n  def update(k : K, v : V) =\n    data(k) = v;\n}\n\ntrait Counter\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends tensor.Counter[K,V] with Tensor1[K,V]\nwith CounterLike[K,V,scala.collection.mutable.Map[K,V],Counter[K,V]];\n\nobject Counter {\n  class Impl[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\n  (override val data : scala.collection.mutable.Map[K,V])\n  (implicit override final val scalar : Scalar[V])\n  extends Counter[K,V] with Serializable;\n\n  /** Returns an empty counter. */\n  def apply[K,V:Scalar]() : Counter[K,V] =\n    new Impl(scala.collection.mutable.HashMap[K,V]());\n\n  /** Returns a counter by summing all the given values. */\n  def apply[K,V:Scalar](values : (K,V)*) : Counter[K,V] =\n    apply(values);\n  \n  /** Returns a counter by summing all the given values. */\n  def apply[K,V:Scalar](values : TraversableOnce[(K,V)]) : Counter[K,V] = {\n    val rv = apply[K,V]();\n    values.foreach({ case (k,v) => rv(k) = rv.scalar.+(v,rv(k)); });\n    rv;\n  }\n\n  /** Counts each of the given items. */\n  def count[K](items : TraversableOnce[K]) : Counter[K,Int] = {\n    val rv = apply[K,Int]();\n    items.foreach(rv(_) += 1);\n    rv;\n  }\n\n  def count[K](items: K*): mutable.Counter[K,Int] = count(items);\n  \n  def apply[K,V:Scalar](domain : Domain1[K]) : Counter[K,V] =\n    new Impl(scala.collection.mutable.HashMap[K,V]());\n\n//  implicit def opCanCopy[K,V:CanCopy] = CanCopy.opMapValues[Counter[K,V],V];\n//  implicit def opZeros[K,V:Scalar] = CanCreateZerosLike.opMapValues[Counter[K,V],V,Counter[K,V]];\n\n  implicit def CanMapValuesCounter\n  [@specialized(Int) K, @specialized(Int,Double) V, @specialized(Int,Double) RV:Scalar]: CanMapValues[Counter[K, V], V, RV, Counter[K, RV]]\n  = new CanMapValues[Counter[K,V],V,RV,Counter[K,RV]] {\n    override def map(from : Counter[K,V], fn : (V=>RV)) = {\n      val rv = Counter[K,RV]();\n      for( (k,v) <- from.pairsIterator) {\n        rv(k) = fn(from.data(k));\n      }\n      rv;\n    }\n\n    override def mapNonZero(from : Counter[K,V], fn : (V=>RV)) = {\n      val rv = Counter[K,RV]();\n      for( (k,v) <- from.pairsIteratorNonZero) {\n        rv(k) = fn(from.data(k));\n      }\n      rv;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Counter2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain._;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._\nimport tensor.Counter2.Curried\nimport scala.collection.mutable.HashMap\n;\n\n/**\n * A mutable tensor that acts like a collection of key1-key2-value pairs backed by\n * a map of maps.\n *\n * @author dlwh,dramage\n */\ntrait Counter2Like\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V,\n +M1[VV]<:Curried[scala.collection.mutable.Map,K1]#Result[VV],\n +T<:scalala.tensor.mutable.Counter[K2,V],\n +This<:Counter2[K1,K2,V]]\nextends tensor.Counter2Like[K1,K2,V,M1,T,This] with Tensor2Like[K1,K2,V,SetDomain[K1], SetDomain[K2], Domain2[K1,K2], Domain2[K2,K1], This] { self =>\n\n  def update(k1 : K1, k2: K2, v : V) =\n    innerGetOrElseUpdate(k1,data)(k2) = v;\n\n  private[mutable] def innerGetOrElseUpdate[M](k:K1, m: scala.collection.mutable.Map[K1,M]): M = {\n    m.getOrElseUpdate(k,m.default(k))\n  }\n}\n\ntrait Counter2\n[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V]\nextends tensor.Counter2[K1,K2,V] with Tensor2[K1,K2,V]\nwith Counter2Like[K1,K2, V,Curried[scala.collection.mutable.Map,K1]#Result,Counter[K2,V],Counter2[K1,K2,V]];\n\nobject Counter2 {\n  class Impl[K1, @specialized(Int,Long) K2, @specialized(Int,Long,Float,Double) V]\n  (override val data : scala.collection.mutable.Map[K1,Counter[K2,V]])\n  (implicit override val scalar : Scalar[V])\n  extends Counter2[K1,K2,V] with Serializable;\n\n  /** Returns a new empty counter. */\n  def apply[K1,K2,V:Scalar]() : Counter2[K1,K2,V] = {\n    val map = new HashMap[K1,Counter[K2,V]] {\n      override def default(k: K1) = Counter[K2,V]();\n    }\n    new Impl[K1,K2,V](map);\n  }\n    \n  /** Aggregates the counts in the given items. */\n  def apply[K1,K2,V:Scalar](values : (K1,K2,V)*) : Counter2[K1,K2,V] =\n    apply(values);\n\n  /** Aggregates the counts in the given items. */\n  def apply[K1,K2,V:Scalar](values : TraversableOnce[(K1,K2,V)]) : Counter2[K1,K2,V] = {\n    val rv = apply[K1,K2,V]();\n    values.foreach({ case (k1,k2,v) => rv(k1,k2) = rv.scalar.+(rv(k1,k2), v) });\n    rv;\n  }\n\n  /** Constructs a Counter2 -- currently ignores the domain. */\n  def apply[K1,K2,V:Scalar](domain : Domain2[K1,K2]) : Counter2[K1,K2,V] =\n    apply[K1,K2,V]();\n  \n  /** Counts the given elements. */\n  def count[K1,K2](values : TraversableOnce[(K1,K2)]) : Counter2[K1,K2,Int] = {\n    val rv = apply[K1,K2,Int]();\n    values.foreach({ case (k1,k2) => rv(k1,k2) += 1; });\n    rv;\n  }\n\n  implicit def canSliceRow[K1,K2,V](implicit vS : Scalar[V])\n  : CanSliceRow[Counter2[K1,K2,V],K1,Counter[K2,V]]\n  = new CanSliceRow[Counter2[K1,K2,V],K1,Counter[K2,V]] {\n    override def apply(from : Counter2[K1,K2,V], row : K1) = from.innerGetOrElseUpdate(row,from.data);\n  }\n  \n  implicit def canSliceCol[K1,K2,V](implicit vS : Scalar[V])\n  : CanSliceCol[Counter2[K1,K2,V],K2,Counter[K1,V]]\n  = new CanSliceCol[Counter2[K1,K2,V],K2,Counter[K1,V]] {\n    override def apply(from : Counter2[K1,K2,V], col : K2) = new Counter[K1,V] {\n      override val data = new scala.collection.mutable.Map[K1,V] {\n        override def apply(k1 : K1) =\n          from(k1,col);\n          \n        override def update(k1 : K1, v : V) =\n          from(k1,col) = v;\n          \n        override def -=(k1 : K1) = {\n          from.data(k1)(col) = vS.zero;\n          this;\n        }\n        \n        override def +=(tup : (K1,V)) = {\n          from.data(tup._1)(col) = (tup._2);\n          this;\n        }\n        \n        override def iterator =\n          for ((k1,map) <- from.data.iterator) yield (k1,map(col));\n          \n        override def get(k1 : K1) =\n          from.data.get(k1).map(_(col));\n          \n        override def keySet = from.data.keySet;\n        \n        override def size = from.data.size;\n      }\n      implicit val scalar = vS;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Matrix.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{IndexDomain,TableDomain};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a MutableTensor that is also a tensor.Matrix.\n *\n * @author dramage\n */\ntrait MatrixLike\n[@specialized(Int,Long,Float,Double,Boolean) V, +This<:Matrix[V]]\nextends tensor.MatrixLike[V,This]\nwith Tensor2Like[Int,Int,V,IndexDomain,IndexDomain,TableDomain,TableDomain,This] {\n  override def t : Matrix[V] =\n    new MatrixTranspose.Impl[V,This](repr);\n}\n\n/**\n * MutableTensor that is also a tensor.Matrix.\n *\n * @author dramage\n */\ntrait Matrix\n[@specialized(Int,Long,Float,Double,Boolean) B]\nextends tensor.Matrix[B]\nwith Tensor2[Int,Int,B]\nwith MatrixLike[B,Matrix[B]];\n\nobject Matrix extends dense.DenseMatrixConstructors {\n  implicit def canSliceRow[V:Scalar] : CanSliceRow[Matrix[V],Int,VectorRow[V]]\n  = new CanSliceRow[Matrix[V],Int,VectorRow[V]] {\n    override def apply(from : Matrix[V], row : Int) =\n      new RowSliceImpl[V,Matrix[V]](from,row);\n  }\n\n  implicit def canSliceCol[V:Scalar] : CanSliceCol[Matrix[V],Int,VectorCol[V]]\n  = new CanSliceCol[Matrix[V],Int,VectorCol[V]] {\n    override def apply(from : Matrix[V], col : Int) =\n      new ColSliceImpl[V,Matrix[V]](from, col);\n  }\n\n  implicit def canSliceMatrix[V:Scalar] : CanSliceMatrix[Matrix[V],Int,Int,Matrix[V]]\n  = new CanSliceMatrix[Matrix[V],Int,Int,Matrix[V]] {\n    override def apply(from : Matrix[V], keys1 : Seq[Int], keys2 : Seq[Int]) =\n      new MatrixSliceImpl[V,Matrix[V]](from, keys1, keys2);\n  }\n\n  trait RowSliceLike[V,+Coll<:Matrix[V],+This<:RowSlice[V,Coll]]\n  extends tensor.Matrix.RowSliceLike[V,Coll,This]\n  with VectorSliceLike[(Int,Int),TableDomain,V,Coll,This] with VectorRowLike[V,This];\n\n  trait RowSlice[V,+Coll<:Matrix[V]]\n  extends tensor.Matrix.RowSlice[V,Coll] with VectorSlice[(Int,Int),V,Coll]\n  with VectorRow[V] with RowSliceLike[V,Coll,RowSlice[V,Coll]];\n\n  class RowSliceImpl[V,+Coll<:Matrix[V]]\n  (override val underlying : Coll, override val row : Int)\n  (implicit override val scalar : Scalar[V])\n  extends tensor.Matrix.RowSliceImpl[V,Coll](underlying,row)\n  with RowSlice[V,Coll];\n\n  trait ColSliceLike[V,+Coll<:Matrix[V],+This<:ColSlice[V,Coll]]\n  extends tensor.Matrix.ColSliceLike[V,Coll,This]\n  with VectorSliceLike[(Int,Int),TableDomain,V,Coll,This] with VectorColLike[V,This];\n\n  trait ColSlice[V,+Coll<:Matrix[V]]\n  extends tensor.Matrix.ColSlice[V,Coll] with VectorSlice[(Int,Int),V,Coll]\n  with VectorCol[V] with ColSliceLike[V,Coll,ColSlice[V,Coll]];\n\n  class ColSliceImpl[V,+Coll<:Matrix[V]]\n  (override val underlying : Coll, override val col : Int)\n  (implicit override val scalar : Scalar[V])\n  extends tensor.Matrix.ColSliceImpl[V,Coll](underlying,col)\n  with ColSlice[V,Coll];\n\n  trait MatrixSliceLike[@specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll<:Matrix[V], +This<:MatrixSlice[V,Coll]]\n  extends tensor.Matrix.MatrixSliceLike[V,Coll,This]\n  with TensorSliceLike[(Int,Int),TableDomain,(Int,Int),TableDomain,V,Coll,This]\n  with MatrixLike[V,This] {\n    override def update(i : Int, j : Int, value : V) =\n      underlying.update(lookup1(i), lookup2(j), value);\n  }\n\n  trait MatrixSlice[@specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll<:Matrix[V]]\n  extends tensor.Matrix.MatrixSlice[V,Coll] with TensorSlice[(Int,Int),(Int,Int),V,Coll]\n  with Matrix[V] with MatrixSliceLike[V,Coll,MatrixSlice[V,Coll]];\n\n  class MatrixSliceImpl[V, +Coll<:Matrix[V]]\n  (override val underlying : Coll, override val keys1 : Seq[Int], override val keys2 : Seq[Int])\n  (implicit override val scalar : Scalar[V])\n  extends tensor.Matrix.MatrixSliceImpl[V,Coll](underlying,keys1,keys2)\n  with MatrixSlice[V, Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/MatrixTranspose.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{IndexDomain,TableDomain};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * A Transpose of any Matrix type is a Matrix.\n *\n * @author dramage\n */\ntrait MatrixTransposeLike\n[@specialized(Int,Long,Float,Double) V, +Coll <: Matrix[V], +This <: MatrixTranspose[V,Coll]]\nextends tensor.MatrixTransposeLike[V,Coll,This]\nwith Tensor2TransposeLike[Int,Int,V,IndexDomain,IndexDomain,TableDomain,TableDomain,Coll,This]\nwith MatrixLike[V,This] {\n  override def domain = underlying.domain.transpose.asInstanceOf[TableDomain];\n  \n  override def t : Coll =\n    underlying;\n}\n\n/**\n * A Transpose of any Matrix type is a Matrix.\n *\n * @author dramage\n */\ntrait MatrixTranspose[@specialized(Int,Long,Float,Double) V, +Coll <: Matrix[V]]\nextends tensor.MatrixTranspose[V,Coll]\nwith Tensor2Transpose[Int,Int,V,Coll]\nwith Matrix[V] with MatrixTransposeLike[V, Coll, MatrixTranspose[V, Coll]];\n\nobject MatrixTranspose {\n  class Impl[V, +Coll <: Matrix[V]]\n  (override val underlying : Coll)\n  (implicit override val scalar : Scalar[V])\n  extends MatrixTranspose[V,Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{IterableDomain,SetDomain,Domain1,IndexDomain,Domain2,TableDomain};\nimport generic.TensorBuilder;\n\nimport scalala.generic.collection._;\nimport scalala.scalar.Scalar\nimport operators._\n\n\n/**\n * Implementation trait for TensorLike.  Supports assigning,\n * updating, and transforming values.\n *\n * @author dramage\n */\ntrait TensorLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +D<:IterableDomain[K], +Repr<:Tensor[K,V]]\nextends tensor.TensorLike[K, V, D, Repr]\nwith operators.MutableNumericOps[Repr] { self =>\n\n  /**\n   * Update an individual value.  The given key must be in the\n   * map's domain, but need not be in its activeDomain.\n   */\n  def update(key : K, value : V) : Unit;\n\n  /** Tranforms all key value pairs in this map by applying the given function. */\n  def transformPairs(f : (K,V)=>V) =\n    this.foreachPair((k,v) => update(k,f(k,v)));\n\n  /**\n   * Uses the given function to update all elements of the domain\n   * that have a non-zero values (and possibly some that have zeros, too).\n   *\n   * @return true if all elements in the map were visited.\n   */\n  def transformNonZeroPairs(fn : ((K,V)=>V)) : Boolean = {\n    this.transformPairs(fn);\n    true;\n  }\n\n  /** Tranforms all values in this map by applying the given function. */\n  def transformValues(f : V=>V) =\n    this.foreachPair((k,v) => update(k,f(v)));\n\n  /**\n   * Uses the given function to update all elements of the domain\n   * that have a non-zero values (and possibly some that have zeros, too).\n   *\n   * @return true if all elements in the map were visited.\n   */\n  def transformNonZeroValues(fn : (V=>V)) = {\n    this.transformValues(fn);\n    true;\n  }\n\n  /**\n   * Returns a view of this tensor as a builder for itself.  This is used\n   * so that you can construct the appropriate return instance and then\n   * call asBuilder to get a builder view of it.\n   */\n  def asBuilder : TensorBuilder[K,V,Tensor[K,V]] = new TensorBuilder[K,V,Tensor[K,V]] {\n    def update(k : K, v : V) = self(k) = v;\n    def result = repr;\n  }\n}\n\n/**\n * Supports assigning, updating, and transforming values.\n *\n * @author dramage\n */\ntrait Tensor\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V]\nextends tensor.Tensor[K,V] with TensorLike[K,V,IterableDomain[K],Tensor[K,V]];\n\nobject Tensor extends TensorImplicitsLevel1 {\n  /** Constructs a tensor for the given domain. */\n  def apply[K,V:Scalar](domain : IterableDomain[K]) : Tensor[K,V] = domain match {\n    case d : IndexDomain => VectorCol(d);\n    case d : Domain1[_] => Tensor1(d);\n    case d : TableDomain => Matrix(d);\n    case d : Domain2[_,_] => Tensor2(d);\n    case _ => new Impl[K,V](domain, scala.collection.mutable.Map[K,V]());\n  }\n\n  /** Default implementation on a closed domain. */\n  class Impl[K, V]\n  (override val domain : IterableDomain[K],\n   protected val data : scala.collection.mutable.Map[K,V])\n  (implicit override val scalar : Scalar[V])\n  extends Tensor[K, V] {\n    override def size = domain.size;\n  \n    override def apply(key : K) : V = {\n      checkKey(key);\n      data.getOrElse(key, scalar.zero);\n    }\n\n    override def update(key : K, value : V) = {\n      checkKey(key);\n      data.update(key, value);\n    }\n  }\n\n  implicit def canSliceTensor[K1, K2, V:Scalar] =\n  new CanSliceTensor[Tensor[K1,V], K1, K2, Tensor[K2,V]] {\n    override def apply(from : Tensor[K1,V], keymap : scala.collection.Map[K2,K1]) =\n      new TensorSlice.FromKeyMap[K1, K2, V, Tensor[K1,V]](from, keymap);\n  }\n\n  implicit def canSliceVector[K, V:Scalar] =\n  new CanSliceVector[Tensor[K,V], K, VectorCol[V]] {\n    override def apply(from : Tensor[K,V], keys : Seq[K]) =\n      new VectorColSlice.FromKeySeq[K,V,Tensor[K,V]](from, keys);\n  }\n}\n\n/**\n * Low priority implicits for mutable tensor updates (with cast).\n *\n * @author dramage\n */\ntrait TensorImplicitsLevel0 {\n  implicit def opSetTensorTensorCast[K,V1,V2,A,B]\n  (implicit v1 : A=>Tensor[K,V1], v2 : B=>tensor.Tensor[K,V2], cast : CanCast[V2,V1],\n   jj : CanJoin[A,B,K,V1,V2])\n  : BinaryUpdateOp[A,B,OpSet]\n  = new BinaryUpdateOp[A,B,OpSet] {\n    def opType = OpSet;\n    override def apply(a : A, b : B) = {\n      val _a = v1(a);\n      jj.joinAll(a,b,(k,v1,v2) => _a(k) = cast(v2));\n    }\n  }\n  \n  implicit def opSetTensorScalarCast[K,V1,V2]\n  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])\n  : BinaryUpdateOp[Tensor[K,V1],V2,OpSet]\n  = new BinaryUpdateOp[Tensor[K,V1],V2,OpSet] {\n    def opType = OpSet;\n    override def apply(a : Tensor[K,V1], b : V2) = {\n      val newV = cast(b);\n      a.transformPairs((k,oldV) => newV);\n    }\n  }\n}\n\n/**\n * Higher priority implicits for mutable tensor updates (no cast).\n *\n * @author dramage\n */\ntrait TensorImplicitsLevel1 extends TensorImplicitsLevel0 {\n  implicit def opUpdateTensorTensor[K,V1,V2,Op<:OpType,A,B]\n  (implicit v1 : A=>Tensor[K,V1], v2 : B=>tensor.Tensor[K,V2],\n   op : BinaryOp[V1,V2,Op,V1], jj : CanJoin[A,B,K,V1,V2])\n  : BinaryUpdateOp[A,B,Op]\n  = new BinaryUpdateOp[A,B,Op] {\n    override def opType = op.opType;\n    override def apply(a : A, b : B) = {\n      val _a = v1(a);\n      jj.joinEitherNonZero(a,b,(k,v1,v2) => _a(k) = op(v1,v2));\n    }\n  }\n  \n  implicit def opSetTensorTensor[K,V,A,B]\n  (implicit v1 : A=>Tensor[K,V], v2 : B=>tensor.Tensor[K,V],\n   jj : CanJoin[A,B,K,V,V])\n  : BinaryUpdateOp[A,B,OpSet]\n  = new BinaryUpdateOp[A,B,OpSet] {\n    def opType = OpSet;\n    override def apply(a : A, b : B) = {\n      val _a = v1(a);\n      jj.joinAll(a,b,(k,v1,v2) => _a(k) = v2);\n    }\n  }\n\n  // uses a view to reduce its priority\n  implicit def opUpdateTensorScalar[K,V1,V2,A,Op<:OpType]\n  (implicit v1: A=>Tensor[K,V1], op : BinaryOp[V1,V2,Op,V1], s : Scalar[V2])\n  : BinaryUpdateOp[A,V2,Op]\n  = new BinaryUpdateOp[A,V2,Op] {\n    override def opType = op.opType;\n    override def apply(a : A, b : V2) = {\n      a.transformValues(v => op(v, b));\n    }\n  }\n  \n  implicit def opSetTensorScalar[K,V:Scalar]\n  : BinaryUpdateOp[Tensor[K,V],V,OpSet]\n  = new BinaryUpdateOp[Tensor[K,V],V,OpSet] {\n    def opType = OpSet;\n    override def apply(a : Tensor[K,V], b : V) = {\n      a.transformPairs((k,v) => b);\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.Domain1;\n\nimport scalala.scalar.Scalar;\n\n/**\n * Implementation trait for mutable Tensor1 instances.\n *\n * @author dramage\n */\ntrait Tensor1Like\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], +This<:Tensor1[K,V]]\nextends tensor.Tensor1Like[K,V,D,This] with TensorLike[K,V,D,This];\n\n/**\n * Mutable tensor.Tensor1.\n *\n * @author dramage\n */\ntrait Tensor1\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends tensor.Tensor1[K,V] with Tensor[K,V]\nwith Tensor1Like[K,V,Domain1[K],Tensor1[K,V]];\n\nobject Tensor1 {\n  /** Constructs a closed-domain tensor for the given domain. */\n  def apply[K,V:Scalar](domain : Domain1[K]) =\n    Tensor1Col(domain);\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1Col.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{Domain1,IndexDomain};\n\nimport scalala.scalar.Scalar;\n\n/**\n * Implementation trait for mutable Tensor1Col instances.\n *\n * @author dramage\n */\ntrait Tensor1ColLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], +This<:Tensor1Col[K,V]]\nextends tensor.Tensor1ColLike[K,V,D,This] with Tensor1Like[K,V,D,This] {\n\n  override def t : Tensor1Row[K,V] =\n    new Tensor1Row.View[K,V](repr);\n}\n\n/**\n * Mutable tensor.Tensor1Col.\n *\n * @author dramage\n */\ntrait Tensor1Col\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends tensor.Tensor1Col[K,V] with Tensor1[K,V]\nwith Tensor1ColLike[K,V,Domain1[K],Tensor1Col[K,V]];\n\nobject Tensor1Col {\n  /** Constructs a closed-domain tensor for the given domain. */\n  def apply[K,V:Scalar](domain : Domain1[K]) : Tensor1Col[K,V] = domain match {\n    case d : IndexDomain => VectorCol(d);\n    case _ => new Impl(domain, scala.collection.mutable.Map[K,V]());\n  }\n\n  class Impl[K,V:Scalar](\n    override val domain : Domain1[K],\n    override protected val data : scala.collection.mutable.Map[K,V])\n  extends Tensor.Impl[K,V](domain, data) with Tensor1Col[K,V];\n\n  class View[K,V](override val inner : Tensor1Row[K,V])\n  extends Tensor1Proxy[K,V,Tensor1Row[K,V]] with Tensor1Col[K,V]\n  with Tensor1Like[K,V,Domain1[K],View[K,V]] {\n    override def repr : View[K,V] = this;\n    override def t : Tensor1Row[K,V] = inner;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1Row.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{Domain1,IndexDomain};\n\nimport scalala.generic.collection.{CanSliceVector};\n\nimport scalala.scalar.Scalar;\n\n/**\n * Implementation trait for mutable Tensor1Row instances.\n *\n * @author dramage\n */\ntrait Tensor1RowLike\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V,\n +D<:Domain1[K], +This<:Tensor1Row[K,V]]\nextends tensor.Tensor1RowLike[K,V,D,This] with Tensor1Like[K,V,D,This] {\n\n  override def t : Tensor1Col[K,V] =\n    new Tensor1Col.View[K,V](repr);\n}\n\n/**\n * Mutable tensor.Tensor1Row.\n *\n * @author dramage\n */\ntrait Tensor1Row\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V]\nextends tensor.Tensor1Row[K,V] with Tensor1[K,V]\nwith Tensor1RowLike[K,V,Domain1[K],Tensor1Row[K,V]];\n\nobject Tensor1Row {\n  /** Constructs a closed-domain tensor for the given domain. */\n  def apply[K,V:Scalar](domain : Domain1[K]) : Tensor1Row[K,V] = domain match {\n    case d : IndexDomain => VectorRow(d);\n    case _ => new Impl(domain, scala.collection.mutable.Map[K,V]());\n  }\n\n  class Impl[K,V:Scalar](\n    override val domain : Domain1[K],\n    override protected val data : scala.collection.mutable.Map[K,V])\n  extends Tensor.Impl[K,V](domain, data) with Tensor1Row[K,V];\n  \n  class View[K,V](override val inner : Tensor1Col[K,V])\n  extends Tensor1Proxy[K,V,Tensor1Col[K,V]] with Tensor1Row[K,V]\n  with Tensor1Like[K,V,Domain1[K],View[K,V]] {\n    override def repr : View[K,V] = this;\n    override def t : Tensor1Col[K,V] = inner;\n  }\n  \n  implicit def canSliceVectorRow[K, V:Scalar] =\n  new CanSliceVector[Tensor[K,V], K, VectorRow[V]] {\n    override def apply(from : Tensor[K,V], keys : Seq[K]) =\n      new VectorRowSlice.FromKeySeq[K,V,Tensor[K,V]](from, keys);\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1Slice.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{IterableDomain,Domain1};\n\nimport scalala.scalar.Scalar;\n\n/**\n * Implementation trait for a Tensor1 view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait Tensor1SliceLike\n[@specialized(Int,Long) K1, +D1<:IterableDomain[K1],\n @specialized(Int,Long) K2, +D2<:Domain1[K2],\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll<:Tensor[K1,V],\n +This<:Tensor1Slice[K1,K2,V,Coll]]\nextends tensor.Tensor1SliceLike[K1,D1,K2,D2,V,Coll,This]\nwith TensorSliceLike[K1, D1, K2, D2, V, Coll, This]\nwith Tensor1Like[K2, V, D2, This];\n\n/**\n * K Tensor1 view of a slice of keys from a Tensor.\n *\n * @author dramage\n */\ntrait Tensor1Slice\n[@specialized(Int,Long) K1, @specialized(Int,Long) K2,\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll<:Tensor[K1,V]]\nextends tensor.Tensor1Slice[K1,K2,V,Coll]\nwith TensorSlice[K1,K2,V,Coll] with Tensor1[K2,V]\nwith Tensor1SliceLike[K1, IterableDomain[K1], K2, Domain1[K2], V, Coll, Tensor1Slice[K1, K2, V, Coll]];\n\nobject Tensor1Slice {\n  /** This view is a no-op but is needed for correct implicit resolution. */\n  implicit def asTensor1[K,V](slice : Tensor1Slice[K,_,V,_]) : Tensor1[K,V] =\n    slice;\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor2.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{Domain1,Domain2,SetDomain,TableDomain};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a mutable tensor.Tensor2.\n *\n * @author dramage\n */\ntrait Tensor2Like\n[@specialized(Int) K1, @specialized(Int) K2,\n @specialized(Int,Long,Float,Double,Boolean) V,\n +D1<:Domain1[K1], +D2<:Domain1[K2], +D<:Domain2[K1,K2], +T<:Domain2[K2,K1],\n +This<:Tensor2[K1,K2,V]]\nextends tensor.Tensor2Like[K1,K2,V,D1,D2,D,T,This]\nwith TensorLike[(K1,K2),V,D,This] { self =>\n\n  /** Updates the value indexed by (i,j). */\n  def update(i : K1, j : K2, value : V) : Unit;\n\n  /** Fixed alias for update(i,j,value). */\n  /* final */ override def update(pos : (K1,K2), value : V) : Unit =\n    update(pos._1, pos._2, value);\n\n  /** Tranforms all key value pairs in this map by applying the given function. */\n  def transformTriples(f : (K1,K2,V)=>V) =\n    transformPairs((k,v) => f(k._1, k._2, v));\n    \n  override def t : Tensor2[K2,K1,V] =\n    new Tensor2Transpose.Impl[K2,K1,V,This](repr)\n}\n\n/**\n * Mutable tensor.Tensor2.\n *\n * @author dramage\n */\ntrait Tensor2\n[@specialized(Int) K1, @specialized(Int) K2,\n @specialized(Int,Long,Float,Double,Boolean) V]\nextends Tensor[(K1,K2),V]\nwith tensor.Tensor2[K1,K2,V]\nwith Tensor2Like[K1,K2,V,Domain1[K1],Domain1[K2],Domain2[K1,K2],Domain2[K2,K1],Tensor2[K1,K2,V]];\n\n\nobject Tensor2 {\n  /** Constructs a closed-domain tensor for the given domain. */\n  def apply[K1,K2,V:Scalar](domain : Domain2[K1,K2]) : Tensor2[K1,K2,V] = domain match {\n    case d : TableDomain => Matrix(d);\n    case _ => new Impl(domain, scala.collection.mutable.Map[(K1,K2),V]());\n  }\n\n  class Impl[K1,K2,V:Scalar]\n  (override val domain : Domain2[K1,K2],\n   protected override val data : scala.collection.mutable.Map[(K1,K2),V])\n  extends Tensor.Impl[(K1,K2),V](domain, data) with Tensor2[K1,K2,V] {\n    override def apply(k1 : K1, k2 : K2) : V = {\n      checkKey(k1,k2);\n      data.getOrElse((k1,k2),scalar.zero);\n    }\n\n    override def update(k1 : K1, k2 : K2, value : V) = {\n      checkKey(k1,k2);\n      data.update((k1,k2), value);\n    }\n  }\n\n  implicit def canSliceRow[T2<:Tensor2[K1,K2,V],K1,K2,V:Scalar] : CanSliceRow[T2,K1,Tensor1Row[K2,V]]\n  = new CanSliceRow[T2,K1,Tensor1Row[K2,V]] {\n    override def apply(from : T2, row : K1) =\n      new RowSliceImpl[K1,K2,V,T2](from,row);\n  }\n\n  implicit def canSliceCol[K1,K2,V:Scalar] : CanSliceCol[Tensor2[K1,K2,V],K2,Tensor1Col[K1,V]]\n  = new CanSliceCol[Tensor2[K1,K2,V],K2,Tensor1Col[K1,V]] {\n    override def apply(from : Tensor2[K1,K2,V], col : K2) =\n      new ColSliceImpl[K1,K2,V,Tensor2[K1,K2,V]](from, col);\n  }\n\n  implicit def canSliceMatrix[K1,K2,V:Scalar]\n  : CanSliceMatrix[Tensor2[K1,K2,V],K1,K2,Matrix[V]]\n  = new CanSliceMatrix[Tensor2[K1,K2,V],K1,K2,Matrix[V]] {\n    override def apply(from : Tensor2[K1,K2,V], keys1 : Seq[K1], keys2 : Seq[K2]) =\n      new MatrixSliceImpl[K1,K2,V,Tensor2[K1,K2,V]](from, keys1, keys2);\n  }\n\n  trait RowSliceLike[K1,K2,V,+Coll<:Tensor2[K1,K2,V],+This<:RowSlice[K1,K2,V,Coll]]\n  extends tensor.Tensor2.RowSliceLike[K1,K2,V,Coll,This]\n  with Tensor1SliceLike[(K1,K2),Domain2[K1,K2],K2,Domain1[K2],V,Coll,This]\n  with Tensor1RowLike[K2,V,Domain1[K2],This];\n\n  trait RowSlice[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  extends tensor.Tensor2.RowSlice[K1,K2,V,Coll]\n  with Tensor1Slice[(K1,K2),K2,V,Coll] with Tensor1Row[K2,V]\n  with RowSliceLike[K1,K2,V,Coll,RowSlice[K1,K2,V,Coll]];\n\n  class RowSliceImpl[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  (override val underlying : Coll, override val row : K1)\n  (implicit override val scalar : Scalar[V])\n  extends tensor.Tensor2.RowSliceImpl[K1,K2,V,Coll](underlying,row)\n  with RowSlice[K1,K2,V,Coll];\n\n  trait ColSliceLike[K1,K2,V,+Coll<:Tensor2[K1,K2,V],+This<:ColSlice[K1,K2,V,Coll]]\n  extends tensor.Tensor2.ColSliceLike[K1,K2,V,Coll,This]\n  with Tensor1SliceLike[(K1,K2),Domain2[K1,K2],K1,Domain1[K1],V,Coll,This]\n  with Tensor1ColLike[K1,V,Domain1[K1],This]\n\n  trait ColSlice[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  extends tensor.Tensor2.ColSlice[K1,K2,V,Coll]\n  with Tensor1Slice[(K1,K2),K1,V,Coll] with Tensor1Col[K1,V]\n  with ColSliceLike[K1,K2,V,Coll,ColSlice[K1,K2,V,Coll]];\n\n  class ColSliceImpl[K1,K2,V,+Coll<:Tensor2[K1,K2,V]]\n  (override val underlying : Coll, override val col : K2)\n  (implicit override val scalar : Scalar[V])\n  extends tensor.Tensor2.ColSliceImpl[K1,K2,V,Coll](underlying,col)\n  with ColSlice[K1,K2,V,Coll];\n\n  trait MatrixSliceLike\n  [@specialized(Int) K1, @specialized(Int) K2,\n   @specialized(Int,Long,Float,Double,Boolean) V,\n   +D1<:Domain1[K1],\n   +D2<:Domain1[K2],\n   +D<:Domain2[K1,K2],\n   +T<:Domain2[K2,K1],\n   +Coll<:Tensor2[K1,K2,V],\n   +This<:MatrixSlice[K1,K2,V,Coll]]\n  extends tensor.Tensor2.MatrixSliceLike[K1,K2,V,D1,D2,D,T,Coll,This]\n  with TensorSliceLike[(K1,K2),D,(Int,Int),TableDomain,V,Coll,This]\n  with MatrixLike[V,This] {\n    override def update(i : Int, j : Int, value : V) =\n      underlying.update(lookup1(i), lookup2(j), value);\n  }\n\n  trait MatrixSlice\n  [@specialized(Int,Long) K1, @specialized(Int,Long) K2,\n   @specialized(Int,Long,Float,Double,Boolean) V,\n   +Coll<:Tensor2[K1,K2,V]]\n  extends tensor.Tensor2.MatrixSlice[K1,K2,V,Coll]\n  with TensorSlice[(K1,K2),(Int,Int),V,Coll]\n  with Matrix[V]\n  with MatrixSliceLike[K1,K2,V,Domain1[K1],Domain1[K2],Domain2[K1,K2],Domain2[K2,K1],Coll,MatrixSlice[K1,K2,V,Coll]];\n\n  class MatrixSliceImpl[K1, K2, V, +Coll<:Tensor2[K1,K2,V]]\n  (override val underlying : Coll, override val keys1 : Seq[K1], override val keys2 : Seq[K2])\n  (implicit override val scalar : Scalar[V])\n  extends tensor.Tensor2.MatrixSliceImpl[K1,K2,V,Coll](underlying,keys1,keys2)\n  with MatrixSlice[K1, K2, V, Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor2Transpose.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{Domain1,Domain2};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a transposed view of an underlying MutableTensor2.\n *\n * @author dramage\n */\ntrait Tensor2TransposeLike\n[@specialized(Int) K2, @specialized(Int) K1,\n @specialized(Int,Long,Float,Double,Boolean) V,\n +D2<:Domain1[K2], +D1<:Domain1[K1], +T<:Domain2[K2,K1], +D<:Domain2[K1,K2],\n +Coll<:Tensor2[K1,K2,V],\n +This<:Tensor2Transpose[K2,K1,V,Coll]]\nextends tensor.Tensor2TransposeLike[K2,K1,V,D2,D1,T,D,Coll,This]\nwith TensorSliceLike[(K1,K2),D,(K2,K1),T,V,Coll,This]\nwith Tensor2Like[K2,K1,V,D2,D1,T,D,This] {\nself =>\n\n  override def update(i : K2, j : K1, value : V) =\n    underlying.update(j, i, value);\n  \n  override def t : Coll =\n    underlying;\n}\n\n/**\n * Transposed view of an undelrying MutableTensor2.\n *\n * @author dramage\n */\ntrait Tensor2Transpose\n[@specialized(Int) K2, @specialized(Int) K1,\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll <: Tensor2[K1,K2,V]]\nextends tensor.Tensor2Transpose[K2,K1,V,Coll]\nwith TensorSlice[(K1,K2),(K2,K1),V,Coll]\nwith Tensor2[K2,K1,V]\nwith Tensor2TransposeLike[K2,K1,V,Domain1[K2],Domain1[K1],Domain2[K2,K1],Domain2[K1,K2],Coll,Tensor2Transpose[K2,K1,V,Coll]];\n\nobject Tensor2Transpose {\n  /** Default implementation. */\n  class Impl[K2, K1, V:Scalar, +Coll <: Tensor2[K1,K2,V]](underlying : Coll)\n  extends tensor.Tensor2Transpose.Impl[K2,K1,V,Coll](underlying)\n  with Tensor2Transpose[K2,K1,V,Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/TensorProxy.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{Domain1,IterableDomain,IndexDomain};\n\n/**\n * Proxy for a mutable tensor.\n *\n * @author dramage\n */\ntrait TensorProxyLike\n[@specialized(Int, Long) K,\n @specialized(Int, Long, Float, Double, Boolean) V,\n +D<:IterableDomain[K],\n Inner <: Tensor[K,V],\n +This <: Tensor[K,V]]\nextends tensor.TensorProxyLike[K,V,D,Inner,This] with TensorLike[K,V,D,This] {\n\n  override def update(key : K, value : V) : Unit =\n    inner.update(key, value);\n\n  override def transformPairs(f : (K,V)=>V) =\n    inner.transformPairs(f);\n\n  override def transformNonZeroPairs(fn : ((K,V)=>V)) : Boolean =\n    inner.transformNonZeroPairs(fn);\n\n  override def transformValues(f : V=>V) =\n    inner.transformValues(f);\n\n  override def transformNonZeroValues(fn : (V=>V)) =\n    inner.transformNonZeroValues(fn);\n}\n\n/**\n * A proxy for a mutable Tensor.\n *\n * @author dramage\n */\ntrait TensorProxy[@specialized(Int,Long) A, @specialized(Int,Long,Float,Double,Boolean) B, Inner <: Tensor[A,B]]\nextends tensor.TensorProxy[A,B,Inner] with Tensor[A,B] with TensorProxyLike[A,B,IterableDomain[A],Inner,TensorProxy[A,B,Inner]];\n\n/**\n * A proxy for a mutable Tensor1.\n * \n * @author dramage\n */\ntrait Tensor1ProxyLike\n[@specialized(Int, Long) K,\n @specialized(Int, Long, Float, Double, Boolean) V,\n +D<:Domain1[K],\n Inner <: Tensor1[K,V],\n +This <: Tensor1[K,V]]\nextends tensor.Tensor1ProxyLike[K,V,D,Inner,This]\n   with TensorProxyLike[K,V,D,Inner,This] with Tensor1Like[K,V,D,This];\n\n/**\n * A proxy for a mutable Tensor1.\n *\n * @author dramage\n */\ntrait Tensor1Proxy\n[@specialized(Int, Long) K,\n @specialized(Int, Long, Float, Double, Boolean) V,\n Inner <: Tensor1[K,V]]\nextends tensor.Tensor1Proxy[K,V,Inner]\n   with TensorProxy[K,V,Inner] with Tensor1[K,V]\n   with Tensor1ProxyLike[K,V,Domain1[K],Inner,Tensor1Proxy[K,V,Inner]];\n\n/**\n * A proxy for a mutable Vector.\n *\n * @author dramage\n */\ntrait VectorProxyLike[@specialized(Int,Long,Float,Double) V, Inner<:Vector[V], +This<:Vector[V]]\nextends tensor.VectorProxyLike[V,Inner,This] with Tensor1ProxyLike[Int,V,IndexDomain,Inner,This] with VectorLike[V,This];\n\n/**\n * A proxy for a mutable vector.\n *\n * @author dramage\n */\ntrait VectorProxy[@specialized(Int,Long,Float,Double) V, Inner<:Vector[V]]\nextends tensor.VectorProxy[V,Inner] with Tensor1Proxy[Int,V,Inner] with Vector[V] with VectorProxyLike[V,Inner,VectorProxy[V,Inner]];\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/TensorSlice.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain._;\n\nimport scalala.scalar.Scalar;\n\n/**\n * Implementation trait for slices of an underlying Tensor.  A slice\n * is a pass-through view of a (mapped) subset of the original Tensor's\n * domain.\n *\n * @author dramage\n */\ntrait TensorSliceLike\n[@specialized(Int,Long) K1, +D1<:IterableDomain[K1],\n @specialized(Int,Long) K2, +D2<:IterableDomain[K2],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K1,V],\n +This<:TensorSlice[K1,K2,V,Coll]]\nextends tensor.TensorSliceLike[K1,D1,K2,D2,V,Coll,This]\nwith TensorLike[K2,V,D2,This] {\n\n  override def update(key : K2, value : V) =\n    underlying.update(lookup(key), value);\n}\n\n/**\n * Pass-through view of a (key-mapped) subset of an underlying Tensor.\n *\n * @author dramage\n */\ntrait TensorSlice\n[@specialized(Int,Long) K1, @specialized(Int,Long) K2,\n @specialized(Int,Long,Float,Double,Boolean) V, +Coll <: Tensor[K1, V]]\nextends tensor.TensorSlice[K1,K2,V,Coll] with Tensor[K2,V]\nwith TensorSliceLike[K1, IterableDomain[K1], K2, IterableDomain[K2], V, Coll, TensorSlice[K1, K2, V, Coll]];\n\n\nobject TensorSlice {\n  class FromKeyMap[K1, K2, V:Scalar, +Coll<:Tensor[K1, V]]\n  (underlying : Coll, keymap : scala.collection.Map[K2,K1])\n  extends tensor.TensorSlice.FromKeyMap[K1,K2,V,Coll](underlying, keymap)\n  with TensorSlice[K1,K2,V,Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Vector.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.IndexDomain;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a Tensor that is also a tensor.Vector.\n *\n * @author dramage.\n */\ntrait VectorLike[@specialized(Int,Long,Float,Double,Boolean) V, +Repr<:Vector[V]]\nextends tensor.VectorLike[V,Repr] with Tensor1Like[Int,V,IndexDomain,Repr] {\n\n  /** Returns a view of this vector as a row. Tightens bound superclass's return value. */\n  override def asRow : VectorRow[V] = this match {\n    case r : VectorRow[_] => this.asInstanceOf[VectorRow[V]];\n    case _ => new VectorRow.View(repr);\n  }\n\n  /** Returns a view of this vector as a column. Tightens bound superclass's return value.  */\n  override def asCol : VectorCol[V] = this match {\n    case c : VectorCol[_] => this.asInstanceOf[VectorCol[V]];\n    case _ => new VectorCol.View(repr);\n  }\n\n  def := (seq : Seq[V]) = {\n    checkDomain(IndexDomain(seq.length));\n\n    var i = 0;\n    for (v <- seq) {\n      this(i) = v;\n      i += 1;\n    }\n  }\n\n  def :=[O] (seq : Seq[O])(implicit tf : O=>V) = {\n    checkDomain(IndexDomain(seq.length));\n\n    var i = 0;\n    for (v <- seq) {\n      this(i) = v;\n      i += 1;\n    }\n  }\n\n  /** In-place quick-sort of the values in this sequence. */\n  def sort(implicit ord : Ordering[V]) : Unit =\n    quickSort(0, size);\n\n  /** Adapted from scala.util.Sorting.sort1 */\n  private def quickSort[K](off: Int, len: Int)(implicit ord: Ordering[V]) {\n    import ord._\n    val x = this;\n    @inline def swap(a: Int, b: Int) {\n      val t = x(a)\n      x(a) = x(b)\n      x(b) = t\n    }\n    @inline def vecswap(_a: Int, _b: Int, n: Int) {\n      var a = _a\n      var b = _b\n      var i = 0\n      while (i < n) {\n        swap(a, b)\n        i += 1\n        a += 1\n        b += 1\n      }\n    }\n    @inline def med3(a: Int, b: Int, c: Int) = {\n      if (x(a) < x(b)) {\n        if (x(b) < x(c)) b else if (x(a) < x(c)) c else a\n      } else {\n        if (x(b) > x(c)) b else if (x(a) > x(c)) c else a\n      }\n    }\n    @inline def sort2(off: Int, len: Int) {\n      // Insertion sort on smallest arrays\n      if (len < 7) {\n        var i = off\n        while (i < len + off) {\n          var j = i\n          while (j > off && x(j-1) > x(j)) {\n            swap(j, j-1)\n            j -= 1\n          }\n          i += 1\n        }\n      } else {\n        // Choose a partition element, v\n        var m = off + (len >> 1)        // Small arrays, middle element\n        if (len > 7) {\n          var l = off\n          var n = off + len - 1\n          if (len > 40) {        // Big arrays, pseudomedian of 9\n            var s = len / 8\n            l = med3(l, l+s, l+2*s)\n            m = med3(m-s, m, m+s)\n            n = med3(n-2*s, n-s, n)\n          }\n          m = med3(l, m, n) // Mid-size, med of 3\n        }\n        val v = x(m)\n\n        // Establish Invariant: v* (<v)* (>v)* v*\n        var a = off\n        var b = a\n        var c = off + len - 1\n        var d = c\n        var done = false\n        while (!done) {\n          while (b <= c && x(b) <= v) {\n            if (x(b) == v) {\n              swap(a, b)\n              a += 1\n            }\n            b += 1\n          }\n          while (c >= b && x(c) >= v) {\n            if (x(c) == v) {\n              swap(c, d)\n              d -= 1\n            }\n            c -= 1\n          }\n          if (b > c) {\n            done = true\n          } else {\n            swap(b, c)\n            c -= 1\n            b += 1\n          }\n        }\n\n        // Swap partition elements back to middle\n        val n = off + len\n        var s = math.min(a-off, b-a)\n        vecswap(off, b-s, s)\n        s = math.min(d-c, n-d-1)\n        vecswap(b,   n-s, s)\n\n        // Recursively sort non-partition-elements\n        s = b - a\n        if (s > 1)\n          sort2(off, s)\n        s = d - c\n        if (s > 1)\n          sort2(n-s, s)\n      }\n    }\n    sort2(off, len)\n  }\n}\n\n/**\n * A Vector is a Tensor indexed by Ints on the IndexDomain.\n *\n * @author dramage\n */\ntrait Vector[@specialized(Int,Long,Float,Double,Boolean) V]\nextends tensor.Vector[V] with Tensor1[Int,V]\nwith VectorLike[V,Vector[V]];\n\n\nobject Vector extends dense.DenseVectorConstructors;\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/VectorCol.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.IndexDomain;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for mutable VectorCol instances.\n *\n * @author dramage\n */\ntrait VectorColLike[@specialized(Int,Long,Float,Double) V, +This<:VectorCol[V]]\nextends tensor.VectorColLike[V,This]\nwith Tensor1ColLike[Int,V,IndexDomain,This] with VectorLike[V,This] {\n\n  override def t : VectorRow[V] =\n    new VectorRow.View[V](repr);\n}\n\n/**\n * Mutable tensor.VectorCol.\n *\n * @author dramage\n */\ntrait VectorCol[@specialized(Int,Long,Float,Double) V]\nextends tensor.VectorCol[V] with Tensor1Col[Int,V] with Vector[V]\nwith VectorColLike[V,VectorCol[V]];\n\nobject VectorCol {\n  def apply[V:Scalar](domain : IndexDomain) =\n    dense.DenseVectorCol[V](domain);\n\n  class View[V](override val inner : Vector[V])\n  extends VectorProxy[V,Vector[V]] with tensor.VectorProxy[V,Vector[V]] with VectorCol[V] with VectorLike[V,View[V]] {\n    override def repr : View[V] = this;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/VectorRow.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.IndexDomain;\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for mutable VectorRow instances.\n *\n * @author dramage\n */\ntrait VectorRowLike[@specialized(Int,Long,Float,Double) V, +This<:VectorRow[V]]\nextends tensor.VectorRowLike[V,This]\nwith Tensor1RowLike[Int,V,IndexDomain,This] with VectorLike[V,This] {\n  override def t : VectorCol[V] =\n    new VectorCol.View[V](repr);\n}\n\n/**\n * Mutable tensor.VectorRow.\n *\n * @author dramage\n */\ntrait VectorRow[@specialized(Int,Long,Float,Double) V]\nextends tensor.VectorRow[V] with Tensor1Row[Int,V] with Vector[V]\nwith VectorRowLike[V,VectorRow[V]];\n\nobject VectorRow {\n  def apply[V:Scalar](domain : IndexDomain) =\n    dense.DenseVectorRow[V](domain);\n\n  class View[V](override val inner : Vector[V])\n  extends VectorProxy[V,Vector[V]] with tensor.VectorProxy[V,Vector[V]] with VectorRow[V] with VectorLike[V,View[V]] {\n    override def repr : View[V] = this;\n  }\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/VectorSlice.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage mutable;\n\nimport domain.{IterableDomain,IndexDomain};\n\nimport scalala.scalar.Scalar;\nimport scalala.generic.collection._;\nimport scalala.operators._;\n\n/**\n * Implementation trait for a Vector-like view of a mutable Tensor.\n *\n * @author dramage\n */\ntrait VectorSliceLike\n[@specialized(Int,Long) K, +D<:IterableDomain[K],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K,V],\n +This<:VectorSlice[K,V,Coll]]\nextends tensor.VectorSliceLike[K, D, V, Coll, This]\nwith Tensor1SliceLike[K, D, Int, IndexDomain, V, Coll, This]\nwith VectorLike[V, This];\n\n/**\n * Vector-like view of a mutable Tensor.\n *\n * @author dramage\n */\ntrait VectorSlice\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K, V]]\nextends tensor.VectorSlice[K,V,Coll]\nwith Tensor1Slice[K,Int,V,Coll]\nwith Vector[V]\nwith VectorSliceLike[K, IterableDomain[K], V, Coll, VectorSlice[K, V, Coll]];\n\n\n/**\n * Implementation trait for a VectorRow-like view of a mutable Tensor.\n *\n * @author dramage\n */\ntrait VectorRowSliceLike\n[@specialized(Int,Long) K, +D<:IterableDomain[K],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K,V],\n +This<:VectorRowSlice[K,V,Coll]]\nextends tensor.VectorRowSliceLike[K, D, V, Coll, This]\nwith VectorSliceLike[K, D, V, Coll, This]\nwith VectorRowLike[V, This];\n\n/**\n * VectorRow-like view of a mutable Tensor.\n *\n * @author dramage\n */\ntrait VectorRowSlice\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K, V]]\nextends tensor.VectorRowSlice[K,V,Coll]\nwith VectorSlice[K,V,Coll]\nwith VectorRow[V]\nwith VectorRowSliceLike[K, IterableDomain[K], V, Coll, VectorRowSlice[K, V, Coll]];\n\nobject VectorRowSlice {\n  class FromKeySeq[K, V:Scalar, +Coll<:Tensor[K, V]]\n  (underlying : Coll, keys : Seq[K])\n  extends tensor.VectorRowSlice.FromKeySeq[K,V,Coll](underlying, keys)\n  with VectorRowSlice[K,V,Coll];\n}\n\n/**\n * Implementation trait for a VectorCol-like view of a mutable Tensor.\n *\n * @author dramage\n */\ntrait VectorColSliceLike\n[@specialized(Int,Long) K, +D<:IterableDomain[K],\n @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K,V],\n +This<:VectorColSlice[K,V,Coll]]\nextends tensor.VectorColSliceLike[K, D, V, Coll, This]\nwith VectorSliceLike[K, D, V, Coll, This]\nwith VectorColLike[V, This];\n\n/**\n * VectorCol-like view of a mutable Tensor.\n *\n * @author dramage\n */\ntrait VectorColSlice\n[@specialized(Int,Long) K, @specialized(Int,Long,Float,Double,Boolean) V,\n +Coll<:Tensor[K, V]]\nextends tensor.VectorColSlice[K,V,Coll]\nwith VectorSlice[K,V,Coll]\nwith VectorCol[V]\nwith VectorColSliceLike[K, IterableDomain[K], V, Coll, VectorColSlice[K, V, Coll]];\n\nobject VectorColSlice {\n  class FromKeySeq[K, V:Scalar, +Coll<:Tensor[K, V]]\n  (underlying : Coll, keys : Seq[K])\n  extends tensor.VectorColSlice.FromKeySeq[K,V,Coll](underlying, keys)\n  with VectorColSlice[K,V,Coll];\n}\n\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/package.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\n\npackage object tensor {\n}\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/sparse/SparseArrayTensor.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage sparse;\n\nimport domain.{DomainLike,IterableDomain};\n\nimport scalala.collection.sparse.SparseArray;\nimport scalala.scalar.Scalar;\n\n/**\n * Implementation trait for a tensor backed by a sparse array of values.\n *\n * @author dramage\n */\ntrait SparseArrayTensorLike\n[@specialized(Int,Long) A, @specialized(Int,Long,Float,Double,Boolean) B,\n +D<:IterableDomain[A] with DomainLike[A,D],\n +This<:SparseArrayTensor[A,B]]\nextends mutable.TensorLike[A,B,D,This] {\n  def data : SparseArray[B];\n\n  override def nonzeroSize =\n    data.activeLength;\n\n  /** Assigns the given value to all elements of this map. */\n  def :=(value : B) = {\n    if (value == data.default) {\n      data.clear;\n    } else {\n      var i = 0;\n      while (i < data.length) {\n        data(i) = value;\n        i += 1;\n      }\n    }\n  }\n\n  /** Tranforms all values in this map by applying the given function. */\n  override def transformValues(f : B=>B) =\n    data.transform(f);\n}\n\n/**\n * Mutable tensor by a sparse array of values.\n *\n * @author dramage\n */\ntrait SparseArrayTensor\n[@specialized(Int,Long) A, @specialized(Int,Long,Float,Double,Boolean) B]\nextends mutable.Tensor[A,B]\nwith SparseArrayTensorLike[A,B,IterableDomain[A],SparseArrayTensor[A,B]];\n"
  },
  {
    "path": "src/main/scala/scalala/tensor/sparse/SparseVector.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage sparse;\n\nimport domain.{IterableDomain,IndexDomain};\n\n\nimport scalala.collection.sparse.{SparseArray,DefaultArrayValue};\nimport scalala.scalar.Scalar;\n\nimport scalala.operators._\nimport scalala.generic.collection.{CanCopy, CanCreateZerosLike, CanSliceCol, CanAppendColumns}\nimport dense.DenseVector\n;\n\n/**\n * A vector backed by a SparseArray.\n *\n * @author dramage\n */\n@SerialVersionUID(1)\ntrait SparseVector[@specialized(Int,Long,Float,Double) V]\nextends SparseArrayTensor[Int,V] with SparseArrayTensorLike[Int,V,IndexDomain,SparseVector[V]]\nwith mutable.Vector[V] with mutable.VectorLike[V,SparseVector[V]] with Serializable {\n  override def length = data.length;\n\n  override def apply(key : Int) =\n    data(key);\n\n  override def update(key : Int, value : V) =\n    data(key) = value;\n\n  override def foreachNonZeroKey[U](fn : (Int=>U)) = {\n    data.foreachActiveKey(fn);\n    data.activeLength == data.length;\n  }\n\n  override def foreachNonZeroValue[U](fn : (V=>U)) = {\n    data.foreachActiveValue(fn);\n    data.activeLength == data.length;\n  }\n\n  override def foreachNonZeroPair[U](fn : ((Int,V)=>U)) = {\n    data.foreachActivePair(fn);\n    data.activeLength == data.length;\n  }\n\n  override def pairsIteratorNonZero:Iterator[(Int,V)] = data.activeIterator\n}\n\nobject SparseVector {\n  /** Creates a sparse vector literal. */\n  def apply[V:Scalar:ClassManifest:DefaultArrayValue](values : V*) =\n    new SparseVectorCol(SparseArray(values :_*))\n\n  /** Returns a vector of zeros of the given size. */\n  def zeros[V:Scalar:ClassManifest:DefaultArrayValue](size : Int) =\n    create(size)();\n\n  /** Creates a sparse vector of the given size with given initial values. */\n  def create[V:Scalar:ClassManifest:DefaultArrayValue](size : Int)(values : (Int,V)*) =\n    new SparseVectorCol(SparseArray.create(size)(values :_*));\n\n  /** Tabulate a vector with the value at each offset given by the function. */\n  def tabulate[V:Scalar:ClassManifest:DefaultArrayValue](size : Int)(f : (Int => V)) =\n    new SparseVectorCol(SparseArray.tabulate(size)(f));\n\n\n  /*\n   * Implicits for functions\n   */\n\n    /** Optimized base class for creating zeros */\n  trait CanCreateZerosSparseVector\n  [@specialized V, @specialized RV, SV[V]<:SparseVector[V]]\n    extends CanCreateZerosLike[SV[V],SV[RV]] {\n    def create(length : Int) : SV[RV];\n    def apply(v1: SV[V]) = create(v1.length);\n  }\n\n\n  class GenericSparseVectorRowBase[@specialized V:Scalar:Manifest:DefaultArrayValue] {\n    def create(length : Int) = new SparseVectorRow(new SparseArray[V](length))\n  }\n\n  class GenericSparseVectorColBase[@specialized V:Scalar:Manifest:DefaultArrayValue] {\n    def create(length : Int) = new SparseVectorCol(new SparseArray[V](length))\n  }\n\n  class GenericSparseVectorBase[@specialized V:Scalar:Manifest:DefaultArrayValue] {\n    def create(length : Int) = new SparseVectorCol(new SparseArray[V](length))\n  }\n\n\n  implicit def canCreateZerosSparseVector[@specialized V, @specialized RV:Scalar:Manifest:DefaultArrayValue]\n  : CanCreateZerosSparseVector[V, RV, SparseVector] =\n    new GenericSparseVectorColBase with CanCreateZerosSparseVector[V, RV, SparseVector];\n\n    /** Optimized base class for mapping dense columns. */\n  implicit def canCreateZerosSparseVectorCols[@specialized V, @specialized RV:Scalar:Manifest:DefaultArrayValue]\n  : CanCreateZerosSparseVector[V, RV, SparseVectorCol] =\n  new GenericSparseVectorColBase with CanCreateZerosSparseVector[V, RV, SparseVectorCol];\n\n  /** Optimized base class for mapping dense rows. */\n  implicit def canCreateZerosSparseVectorRows[@specialized V, @specialized RV:Scalar:Manifest:DefaultArrayValue]\n  : CanCreateZerosSparseVector[V, RV, SparseVectorRow] =\n  new GenericSparseVectorRowBase with CanCreateZerosSparseVector[V, RV, SparseVectorRow];\n\n\n  /** Optimized base class for mapping sparse columns. */\n  implicit def canCopySparseVectorCols[@specialized V:Scalar:Manifest] = new CanCopySparseVectorCol[V];\n\n  /** Optimized base class for mapping sparse rows. */\n  implicit def canCopySparseVectorRows[@specialized V:Scalar:Manifest] = new CanCopySparseVectorRow[V];\n\n  /** Optimized base class for mapping sparse . */\n  implicit def canCopySparseVector[@specialized V:Scalar:Manifest] = new CanCopySparseVector[V];\n\n  /** Optimized base class for copying sparse */\n  class CanCopySparseVectorRow[@specialized V:Scalar:ClassManifest] extends CanCopy[SparseVectorRow[V]] {\n    def apply(v1: SparseVectorRow[V]) = {\n      new SparseVectorRow[V](v1.data.copy)\n    }\n  }\n\n  class CanCopySparseVector[@specialized V:Scalar:ClassManifest] extends CanCopy[SparseVector[V]] {\n    def apply(v1: SparseVector[V]) = {\n      new SparseVectorCol[V](v1.data.copy)\n    }\n  }\n\n  class CanCopySparseVectorCol[@specialized V:Scalar:ClassManifest] extends CanCopy[SparseVectorCol[V]] {\n    def apply(v1: SparseVectorCol[V]) = {\n      new SparseVectorCol[V](v1.data.copy)\n    }\n  }\n\n  /* Implicits for operations */\n  implicit object SparseVectorDInnerMulSparseVectorD\n  extends BinaryOp[SparseVectorRow[Double],SparseVectorCol[Double],OpMulRowVectorBy,Double] {\n    override def opType = OpMulRowVectorBy;\n    override def apply(a : SparseVectorRow[Double], b : SparseVectorCol[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n        a dot b\n    }\n  }\n\n  implicit object SparseVectorDDotSparseVectorD\n  extends BinaryOp[SparseVector[Double],SparseVector[Double],OpMulInner,Double] {\n    override def opType = OpMulInner;\n    override def apply(a : SparseVector[Double], b : SparseVector[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n      val aData = a.data\n      val bData = b.data\n      val activeA = aData.activeLength\n      val activeB = bData.activeLength\n\n      var sum = 0.0\n      var ai = 0\n      var bi = 0\n      while(ai < activeA) {\n        while(bi < activeB && bData.indexAt(bi) < aData.indexAt(ai))\n          bi += 1\n        if(bi < activeB && bData.indexAt(bi) == aData.indexAt(ai))\n          sum += bData.valueAt(bi) * aData.valueAt(ai)\n        ai += 1\n      }\n      sum\n    }\n  }\n\n  implicit object SparseVectorDDotDenseVectorD\n  extends BinaryOp[SparseVector[Double],DenseVector[Double],OpMulInner,Double] {\n    override def opType = OpMulInner;\n    override def apply(a : SparseVector[Double], b : DenseVector[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n      val aData = a.data\n      val bData = b.data\n      val activeA = aData.activeLength\n      val bStep = b.stride\n\n      var sum = 0.0\n      var ai = 0\n      var bPos = 0\n      while(ai < activeA) {\n        val aIndex = aData.indexAt(ai)\n        bPos = bStep * aIndex + b.offset\n        sum += bData(bPos) * aData.valueAt(ai)\n        ai += 1\n      }\n      sum\n    }\n  }\n\n  implicit object DenseVectorDDotSparseVectorD\n  extends BinaryOp[DenseVector[Double],SparseVector[Double],OpMulInner,Double] {\n    override def opType = OpMulInner;\n    override def apply(a : DenseVector[Double], b : SparseVector[Double]) = {\n      require(a.length == b.length, \"Vectors must have same length\");\n        b dot a\n    }\n  }\n\n  implicit object VectorDAddSparseVectorDInto\n  extends BinaryUpdateOp[mutable.Vector[Double],SparseVector[Double],OpAdd] {\n    override def opType = OpAdd;\n    override def apply(a : mutable.Vector[Double], b : SparseVector[Double]) {\n      require(a.length == b.length, \"Vectors must have same length\");\n      val bIndex = b.data.indexArray\n      val bData = b.data.rawValueArray\n      val activeB = b.data.activeLength\n\n      var bi = 0\n      while(bi < activeB) {\n        a(bIndex(bi)) += bData(bi)\n        bi += 1\n      }\n    }\n  }\n\n  implicit object SparseVectorDMulDoubleInto\n  extends BinaryUpdateOp[SparseVector[Double],Double,OpMul] {\n    override def opType = OpMul;\n    override def apply(a : SparseVector[Double], b : Double) {\n      val bData = a.data.rawValueArray\n      val activeB = a.data.activeLength\n\n      var bi = 0\n      while(bi < activeB) {\n        bData(bi) *= b\n        bi += 1\n      }\n    }\n  }\n\n  implicit object VectorDSubSparseVectorDInto\n  extends BinaryUpdateOp[mutable.Vector[Double],SparseVector[Double],OpSub] {\n    override def opType = OpSub;\n    override def apply(a : mutable.Vector[Double], b : SparseVector[Double]) {\n      require(a.length == b.length, \"Vectors must have same length\");\n      val bIndex = b.data.indexArray\n      val bData = b.data.rawValueArray\n      val activeB = b.data.activeLength\n\n      var bi = 0\n      while(bi < activeB) {\n        a(bIndex(bi)) -= bData(bi)\n        bi += 1\n      }\n    }\n  }\n\n  implicit def binaryOpFromBinaryUpdateOp[SV<:SparseVector[Double],Other,Op<:OpType](implicit copy: CanCopy[SV], op: BinaryUpdateOp[SV,Other,Op]) = {\n    new BinaryOp[SV,Other,Op,SV] {\n      override def opType = op.opType;\n      override def apply(a : SV, b : Other) = {\n        val c = copy(a)\n        op(c,b)\n        c\n      }\n    }\n  }\n\n  implicit val vspace = scalala.operators.bundles.MutableInnerProductSpace.make[Double,scalala.tensor.sparse.SparseVector[Double]]\n}\n\nclass SparseVectorRow[@specialized(Int,Long,Float,Double) V]\n(override val data : SparseArray[V])\n(implicit override val scalar : Scalar[V])\nextends SparseVector[V] with mutable.VectorRow[V] with mutable.VectorRowLike[V,SparseVectorRow[V]] {\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) = {\n    implicit val mf = implicitly[Scalar[V2]].manifest;\n    implicit val dv = implicitly[Scalar[V2]].defaultArrayValue;\n    domain match {\n      case that : IndexDomain => new SparseVectorRow(new SparseArray[V2](that.size)).asBuilder;\n      case _ => super.newBuilder[K2,V2](domain);\n    }\n  }\n  \n  override def t : SparseVectorCol[V] =\n    new SparseVectorCol(data)(scalar);\n}\n\n/**\n * SparseVectors as a column.\n *\n * @author dramage\n */\nclass SparseVectorCol[@specialized(Int,Long,Float,Double) V]\n(override val data : SparseArray[V])\n(implicit override val scalar : Scalar[V])\nextends SparseVector[V] with mutable.VectorCol[V] with mutable.VectorColLike[V,SparseVectorCol[V]]  {\n  override def newBuilder[K2,V2:Scalar](domain : IterableDomain[K2]) = {\n    implicit val mf = implicitly[Scalar[V2]].manifest;\n    implicit val dv = implicitly[Scalar[V2]].defaultArrayValue;\n    domain match {\n      case that : IndexDomain => new SparseVectorCol(new SparseArray[V2](that.size)).asBuilder;\n      case _ => super.newBuilder[K2,V2](domain);\n    }\n  }\n  \n  override def t : SparseVectorRow[V] =\n    new SparseVectorRow(data)(scalar);\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/collection/sparse/SparseArrayTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.collection.sparse;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass SparseArrayTest extends FunSuite with Checkers {\n  test(\"Map\") {\n    val x = SparseArray(1,0,2,0,3,0,-1,-2,-3);\n    x.compact;\n    val y = x.map(_ + 1);\n    assert(x.length === y.length);\n    assert(x.activeLength === x.length - 3);\n    assert(y.activeLength === y.length - 1);\n    assert(y.toList === List(2,1,3,1,4,1,0,-1,-2));\n  }\n  \n  test(\"Filter\") {\n    val x = SparseArray(1,0,2,0,3,0,-1,-2,-3);\n    x.compact;\n    assert(x.filter(_ % 2 == 1).toList === List(1,3));\n    assert(x.filter(_ % 2 == 1).activeLength === 2);\n    assert(x.filter(_ % 2 == 0).toList === List(0,2,0,0,-2));\n    assert(x.filter(_ % 2 == 0).activeLength === 2);\n    assert(x.filter(_ > 0).toList === List(1,2,3));\n    assert(x.filter(_ > 0).activeLength === 3);\n    assert(x.filter(_ >= 0).toList === List(1,0,2,0,3,0));\n    assert(x.filter(_ >= 0).activeLength === 3);\n    \n    val y = SparseArray(0,1,0,0,-1,-2,-3,-5);\n    y.compact;\n    assert(y.filter(_ > 0).toList === List(1));\n    assert(y.filter(_ >= 0).toList === List(0,1,0,0));\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/generic/CanAssignIntoTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass CanAssignIntoTest extends FunSuite with Checkers {\n\n  import operators.Implicits._;\n\n  test(\"Array[Int]\") {\n    val a = Array(0,0,0);\n    val aRef = a;\n\n    val b = Array(1,2,3);\n    val bRef = b;\n\n    a := b;\n    assert(a.toList === b.toList);\n    assert(!(a eq b));\n    assert((a eq aRef));\n    assert((b eq bRef));\n  }\n\n  test(\"Array[Array[Int]]\") {\n    val a = Array(Array(0,0),Array(0,0),Array(0,0));\n    val aRef = a;\n\n    val b = Array(Array(1,2),Array(3,4),Array(5,6));\n    val bRef = b;\n\n    a := b;\n    assert(a.map(_.toList).toList === b.map(_.toList).toList);\n    assert(!(a eq b));\n    assert((a zip b).forall(tup => !(tup._1 eq tup._2)));\n    assert((a eq aRef));\n    assert((b eq bRef));\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/generic/collection/CanGetDoubleTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith;\n\n@RunWith(classOf[JUnitRunner])\nclass CanGetDoubleTest extends FunSuite with Checkers {\n  def get[Coll,K](coll : Coll, k : K)(implicit get : CanGetDouble[Coll,K]) =\n    get(coll, k);\n\n  test(\"array\") {\n    assert(get(Array(1,2,3),1) === 2.0);\n  }\n\n  test(\"map\") {\n    assert(get(Map('a'->1,'b'->2), 'b') === 2.0);\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/generic/collection/CanGetValueTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith;\n\n@RunWith(classOf[JUnitRunner])\nclass CanGetValueTest extends FunSuite with Checkers {\n  def get[Coll,K,V](coll : Coll, k : K)(implicit get : CanGetValue[Coll,K,V]) =\n    get(coll, k);\n\n  test(\"array\") {\n    assert(get(Array(1.0,2.0,3.0),1) === 2.0);\n  }\n\n  test(\"map\") {\n    assert(get(Map('a'->1,'b'->2), 'b') === 2);\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/generic/collection/CanMapValuesTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage generic;\npackage collection;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith;\n\n@RunWith(classOf[JUnitRunner])\nclass CanMapValuesTest extends FunSuite with Checkers {\n  def toDoubles[From,A,To](coll : From)(implicit map : CanMapValues[From,A,Double,To], cv : A=>Double) =\n    map.map(coll, cv);\n\n  test(\"array\") {\n    assert(toDoubles(Array(1,2,3)).toList === List(1.0,2.0,3.0));\n  }\n\n  test(\"map\") {\n    assert(toDoubles(scala.collection.Map('a'->2,'b'->3)) === Map('a'->2.0,'b'->3.0));\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/library/LibraryTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala\npackage library\n\nimport org.scalatest._\nimport matchers.ShouldMatchers\nimport org.scalatest.junit._\nimport org.scalatest.prop._\nimport org.junit.runner.RunWith\nimport scalala.scalar.Complex\nimport scalala.tensor.mutable.{Matrix, Vector}\nimport Library._\nimport tensor.dense.{DenseVector, DenseMatrix}\n\n@RunWith(classOf[JUnitRunner])\nclass LibraryTest extends FunSuite with Checkers with ShouldMatchers {\n\n  test(\"log\") {\n    assert(log(2.8) === 1.0296194171811581)\n    assert(log(1) === 0)\n    assert(log(Array(1,2,3,4)).toList === List(0.0, 0.6931471805599453, 1.0986122886681098, 1.3862943611198906))\n    assert(log(DenseVector(1,2,3,4)) === DenseVector(0.0, 0.6931471805599453, 1.0986122886681098, 1.3862943611198906))\n    assert(log(DenseMatrix((1,2,3,4))) === DenseMatrix((0.0, 0.6931471805599453, 1.0986122886681098, 1.3862943611198906)))\n  }\n\n  test(\"mean\") {\n    assert(mean(List(Array(0,2),Array(2,4))).toList === List(1,3))\n    assert(mean(List(Array(1.0,3.0),Array(2.0,4.0))).toList === List(1.5,3.5))\n    assert(mean(Iterator(1,2,3)) === 2.0)\n    assert(mean(List(1,2,3,4)) === ((1+2+3+4) / 4.0))\n  }\n\n  test(\"stddev\") {\n    assert(stddev(Array(1,2,3)) === 1.0)\n    assert(stddev(Iterator(1,2,3,4)) === 1.2909944487358056)\n  }\n\n  test(\"sum\") {\n    assert(sum(Matrix((0,2),(2,4))).toList === List(2,6))\n    assert(sum(Matrix((1.0,3.0),(2.0,4.0))).toList === List(3,7))\n    assert(sum(Matrix((1.0,3.0),(2.0,4.0)),Axis.Vertical).toList === List(4,6))\n  }\n\n  test(\"exp\") {\n    exp(1.0296194171811581) should be (2.8)\n    exp(0) should be (1)\n    exp(Array(0.0, 0.6931471805599453, 1.0986122886681098, 1.3862943611198906)) should equal (Array(1,2,3,4))\n    exp(DenseVector(0.0, 0.6931471805599453, 1.0986122886681098, 1.3862943611198906)).toList should equal (List(1,2,3,4))\n    exp(DenseMatrix((0.0, 0.6931471805599453, 1.0986122886681098, 1.3862943611198906))) should equal (DenseMatrix((1,2,3,4)))\n  }\n\n  test(\"Complex:exp\") {\n    // exp(0 + 0i)\n    assert(exp(Complex(0,0)) === Complex(1,0))\n    // exp(0 + Pi * i / 2)\n    val t1 = exp(Complex(0, math.Pi / 2))\n    t1.real should be (0.0 plusOrMinus 1e-10)\n    t1.imag should be (1.0 plusOrMinus 1e-10)\n    // exp(5 + 7i)\n    val t2 = exp(Complex(5, 7))\n    t2.real should be (111.889 plusOrMinus 1e-3)\n    t2.imag should be (97.505 plusOrMinus 1e-3)\n  }\n\n  test(\"Tensor:Norm\") {\n    val v = Array(-0.4326, -1.6656, 0.1253, 0.2877, -1.1465)\n    norm(v, 1) should be (3.6577 plusOrMinus 1e-4)\n    norm(v, 2) should be (2.0915 plusOrMinus 1e-4)\n    norm(v, 3) should be (1.8405 plusOrMinus 1e-4)\n    norm(v, 4) should be (1.7541 plusOrMinus 1e-4)\n    norm(v, 5) should be (1.7146 plusOrMinus 1e-4)\n    norm(v, 6) should be (1.6940 plusOrMinus 1e-4)\n    norm(v, Double.PositiveInfinity) should be (1.6656 plusOrMinus 1e-4)\n  }\n\n  test(\"Tensor:Normalize\") {\n    val v = DenseVector(-0.4326, -1.6656, 0.1253, 0.2877, -1.1465)\n    val norm2V = normalize(v, 2)\n    val norm1V = normalize(v, 1)\n    norm(norm2V, 2) should be (1.0 plusOrMinus 1e-4)\n    norm(norm1V, 1) should be (1.0 plusOrMinus 1e-4)\n  }\n\n  test(\"Tensor:LogNormalize\") {\n    val v = DenseVector(-0.4326, -1.6656, 0.1253, 0.2877, -1.1465)\n    val normed = logNormalize(v)\n    softmax(normed) should be (0.0 plusOrMinus 1e-4)\n  }\n\n  test(\"Matrix:Mean\") {\n    val X = Matrix((9,5,14,4),(2,-12,8,-5),(8,-6,-8,11))\n    val meanV = Vector(6.3333, -4.3333, 4.6666, 3.3333)\n    val meanH = Vector(8., -1.75, 1.25)\n    assert(mean(X, Axis.Horizontal) forallPairs ((i, v) => math.abs(v-meanH(i)) < 1e-4))\n    assert(mean(X, Axis.Vertical) forallPairs ((i, v) => math.abs(v-meanV(i)) < 1e-4))\n  }\n\n  test(\"Matrix:Covariance\") {\n    val X = Matrix((9.,5.,14.,4.),(2.,-12.,8.,-5.),(8.,-6.,-8.,11.))\n    val mu = Vector(8., -1.75, 1.25)\n    val Sigma = Matrix(( 20.6666, 35.3333, -22.0000),\n                       ( 35.3333, 74.9166,  -7.4166),\n                       (-22.0000, -7.4166,  92.9166))\n\n    val (chkSigmaH, chkMuH) = covariance(X, Axis.Horizontal)\n    assert(chkMuH forallPairs ((i, v) => math.abs(v-mu(i)) < 1e-4))\n    assert(chkSigmaH forallPairs ((idx, v) => math.abs(v-Sigma(idx)) < 1e-4))\n\n    val (chkSigmaV, chkMuV) = covariance(X.t, Axis.Vertical)\n    assert(chkMuV forallPairs ((i, v) => math.abs(v-mu(i)) < 1e-4))\n    assert(chkSigmaV forallPairs ((idx, v) => math.abs(v-Sigma(idx)) < 1e-4))\n  }\n\n  test(\"Matrix:MinMax\") {\n    val X = Matrix((9.,5.,14.,4.),(2.,-12.,8.,-5.),(8.,-6.,-8.,11.))\n    min(X, Axis.Horizontal).toArray should be === (Array(4.,-12.,-8.))\n    max(X, Axis.Horizontal).toArray should be === (Array(14.,8.,11.))\n    min(X, Axis.Vertical).toArray should be === (Array(2.,-12.,-8.,-5.))\n    max(X, Axis.Vertical).toArray should be === (Array(9.,5.,14.,11.))\n  }\n\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/library/LinearAlgebraTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage library;\n\nimport org.scalacheck.{Arbitrary,Gen}\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.scalatest.matchers.ShouldMatchers;\nimport org.junit.runner.RunWith;\n\nimport scalala.tensor.dense.DenseVector\nimport scalala.tensor.mutable.{Matrix,Vector}\nimport scalala.library.LinearAlgebra._;\n\n@RunWith(classOf[JUnitRunner])\nclass LinearAlgebraTest extends FunSuite with Checkers with ShouldMatchers {\n  test(\"kron\") {\n    val a = Matrix((1,2),(3,4));\n    val b = Matrix((0,5),(6,7));\n    assert(kron(a,b) === Matrix((0,5,0,10),(6,7,12,14),(0,15,0,20),(18,21,24,28)));\n  }\n\n  test(\"ranks\") {\n    assert(ranks(Array(1,2,3)).toList  === List(1.0,2.0,3.0));\n    assert(ranks(Array(3,-1,2)).toList === List(3.0,1.0,2.0));\n    assert(ranks(Array(1,2,3,3)).toList === List(1.0,2.0,3.5,3.5));\n    assert(ranks(Array(1,2,3,3,3)).toList === List(1.0,2.0,4.0,4.0,4.0));\n  }\n\n  test(\"cholesky\") {\n    val A = Matrix((1.,0.,0.),(2.,3.,0.),(4.,5.,6.))\n    val Sigma = A * A.t\n    assert(cholesky(Sigma) === A)\n  }\n\n  test(\"eigSym\") {\n    val A = Matrix((9.,0.,0.),(0.,82.,0.),(0.,0.,25.))\n    val (lambda, Some(evs)) = eigSym(A, true)\n    assert(lambda === Vector(9.,25.,82.))\n    assert(evs === Matrix((1.,0.,0.),(0.,0.,1.),(0.,1.,0.)))\n  }\n\n  test(\"LUfactorization\") {\n    val (m, _) = LU(Matrix(( 29, 42, -4, 50, 1),\n                           ( 20,-31, 32, 21, 2),\n                           (-47,-20, 24,-22, 3),\n                           (  3, 17,-45, 23, 4)))\n    val aux = Matrix((-47.0000, -20.0000, 24.0000, -22.0000, 3.0000),\n                     ( -0.4255, -39.5106, 42.2127,  11.6382, 3.2765),\n                     ( -0.6170,  -0.7506, 42.4964,  45.1620, 5.3107),\n                     ( -0.0638,  -0.3979, -0.6275,  54.5694, 8.8282))\n    assert(m forallPairs ((idx,v) => math.abs(v-aux(idx)) < 1e-4))\n  }\n\n  test(\"det\") {\n    val A = Matrix((9,26,21),(48,3,11),(7,48,26))\n    det(A) should be (13446.99999999 plusOrMinus 1e-8)\n\n    val B = Matrix((1,2,3),(4,5,-6),(7,8,9))\n    det(B) should be (-72.0 plusOrMinus 1e-15)\n\n    val C = Matrix((1,2,3),(2,4,6),(0,-1,0)) // 1st and 2nd row linearly dep.\n    det(C) should be (0.0 plusOrMinus 1e-15)\n\n    val D = Matrix((-1,1,-1),(1,2,3),(3,-10,1))\n    det(D) should be (-8.0 plusOrMinus 1e-8)\n  }\n\n  test(\"inv\") {\n    val X = Matrix(( 29, 42, -4, 50),\n                   ( 20,-31, 32, 21),\n                   (-47,-20, 24,-22),\n                   (  3, 17,-45, 23))\n    val I = Matrix.eye[Double](4)\n    assert((inv(X) * X) forallPairs ((idx,v) => math.abs(v-I(idx)) < 1e-15))\n  }\n\n  test(\"pinv\") {\n    val X = Matrix((54, 95), (23, 25), (70, 41), (31, 19))\n    val I = Matrix.eye[Double](2)\n    assert((pinv(X) * X) forallPairs ((idx,v) => math.abs(v-I(idx)) < 1e-15))\n  }\n\n  test(\"cross\") {\n    // specific example; with prime elements\n    val (v1, v2, r) = (DenseVector(13, 3, 7), DenseVector(5, 11, 17), DenseVector(-26, -186, 128))\n    assert(cross(v1, v2) === r)\n    assert(cross(v2, v1) === r * -1)\n\n    // test using a re-write of the cross-product equation and a scalacheck arbitrary generator\n    implicit def arb3DVector: Arbitrary[DenseVector[Double]] = Arbitrary {\n      for {\n\tels <- Gen.containerOfN[Array, Double](3, Gen.chooseNum[Double](-100.0, 100.0))\n      } yield DenseVector(els(0), els(1), els(2))\n    }\n    check {(a: DenseVector[Double], b: DenseVector[Double]) =>\n      val r = DenseVector(\n        a(1) * b(2) - a(2) * b(1),\n        a(2) * b(0) - a(0) * b(2),\n        a(0) * b(1) - a(1) * b(0))\n      cross(a, b) == r\n      cross(b, a) == r * -1.0\n    }\n\n    // test the failure that should occur if a or b does not have 3 components\n    val v4comp = DenseVector(1,2,3,4)\n    intercept[IllegalArgumentException] {\n      cross(v4comp, v4comp)\n    }\n  }\n\n  test(\"rank\") {\n    val r1 = Matrix((1.,2.,3.), (1.,2.,3.), (1.,2.,3.))  // rank 1 matrix\n    val r2 = Matrix((1.,2.,3.), (4.,5.,6.), (7.,8.,9.))  // rank 2 matrix\n    val r3 = Matrix((1.,2.,3.), (4.,5.,6.), (6.,8.,9.))  // rank 3 matrix\n    assert(rank(r1) === 1)\n    assert(rank(r2) === 2)\n    assert(rank(r3) === 3)\n  }\n\n  test(\"qr\") {\n    val A = Matrix((1.0, 1.0, 1.0), (4.0, 2.0, 1.0), (16.0, 4.0, 1.0))\n    val (_Q, _R) = qr(A)\n\n    val expectedQ = Matrix((-0.06052275326,-0.6022239035,-0.7960297521),\n                           (-0.2420910130,-0.7648243574,0.5970223140),\n                           (-0.9683640522,0.2288450833,-0.09950371901))\n    _Q.numRows should  be (expectedQ.numRows)\n    _Q.numCols should  be (expectedQ.numCols)\n    _Q foreachPair { case ((i,j), v) => v should be (expectedQ(i,j) plusOrMinus 1e-8) }\n\n    val expectedR = Matrix((-16.52271164,-4.418160988,-1.270977818),\n      (0.,-1.216492285,-1.138203178),\n      (0.,0.,-0.2985111571))\n    _R.numRows should  be (expectedR.numRows)\n    _R.numCols should  be (expectedR.numCols)\n    _R foreachPair { case ((i,j), v) => v should be (expectedR(i,j) plusOrMinus 1e-8) }\n  }\n\n}\n"
  },
  {
    "path": "src/test/scala/scalala/library/NumericsTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.library\n\nimport org.scalatest._\nimport org.scalatest.junit._\nimport org.scalatest.prop._\nimport org.scalatest.matchers.ShouldMatchers\nimport org.junit.runner.RunWith\nimport Library._\nimport Numerics._\nimport org.scalacheck.{Prop, Arbitrary}\n\n@RunWith(classOf[JUnitRunner])\nclass NumericsTest extends FunSuite with Checkers with ShouldMatchers {\n\n  test(\"logSum\") {\n    logSum(log(5), log(2)) should be (log(7) plusOrMinus 1e-10)\n    logSum(log(2), log(5)) should be (log(7) plusOrMinus 1e-10)\n    logSum(Double.NegativeInfinity, log(5)) should be (log(5) plusOrMinus 1e-10)\n    logSum(log(5), Double.NegativeInfinity) should be (log(5) plusOrMinus 1e-10)\n    logSum(Double.NegativeInfinity, Double.NegativeInfinity) should be (Double.NegativeInfinity)\n\n    logSum(log(1), log(2), log(3)) should be (log(6) plusOrMinus 1e-10)\n    logSum(log(1), log(2), Double.NegativeInfinity) should be (log(3) plusOrMinus(1e-10))\n\n    val s = Array.tabulate[Double](5)(i => log1p(i))\n    logSum(s.iterator, s.max) should be (log(15) plusOrMinus 1e-10)\n    logSum(s) should be (log(15) plusOrMinus 1e-10)\n    logSum(Double.NegativeInfinity +: s) should be (log(15) plusOrMinus 1e-10)\n    logSum(s :+ Double.NegativeInfinity) should be (log(15) plusOrMinus 1e-10)\n  }\n\n  test(\"logDiff\") {\n    logDiff(log(5), log(2)) should be (log(3) plusOrMinus 1e-10)\n    logDiff(log(5), log(5)) should be (Double.NegativeInfinity)\n\n    evaluating {\n      logDiff(log(5), log(6))\n    } should produce [IllegalArgumentException]\n  }\n\n  import Arbitrary._;\n  implicit def ae(x: Double) = new {\n    def =~=(y: Double) = (x-y).abs/x < 1E-6;\n  }\n\n  // TODO 2.9 filter out Double.MaxValue.\n  /*test(\"logsumming is approximately associative\") {\n    check(Prop.forAll { (a: Double, b:Double, c: Double) =>\n      logSum(a,logSum(b,c)) =~= logSum(logSum(a,b),c);\n    })\n    check(Prop.forAll { (a: Double, b:Double, c: Double) =>\n      logSum(a,logSum(b,c)) =~= logSum(a,b,c);\n    })\n  }\n\n  test(\"sum distributes over logsum\") {\n    check(Prop.forAll { (a: Double, b:Double, c: Double) =>\n      (a + logSum(b,c)) =~= (logSum(a + b,a+c));\n    })\n  }*/\n\n}\n"
  },
  {
    "path": "src/test/scala/scalala/library/RandomTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.library\n\nimport org.scalatest._\nimport org.scalatest.junit._\nimport org.scalatest.prop._\nimport org.junit.runner.RunWith\nimport scalala.library.Random._\nimport scalala.library.Library._\nimport scalala.tensor.dense._\n\n@RunWith(classOf[JUnitRunner])\nclass RandomTest extends FunSuite with Checkers {\n\n  test(\"MultivariateGaussian\") {\n    // specify rng explicitly so that we don't ever fail this test\n    implicit val mt = new random.MersenneTwisterFast(0l);\n\n    val Sigma = DenseMatrix((3., 4.), (4., 16.))\n    val mu    = DenseVector(77.,-3.)\n    val X     = DenseMatrix.randn(mu, Sigma, 50000)(mt)\n\n    val (chkSigma, chkMu) = covariance(X, Axis.Horizontal)\n    assert(chkMu forallPairs ( (i,v) => math.abs(v-mu(i)) < 1e-1 ),chkMu)\n    assert(chkSigma forallPairs ( (idx,v) => math.abs(v-Sigma(idx)) < 1e-1 ), chkSigma)\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/library/StatisticsTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.library\n\nimport org.scalatest._;\nimport org.scalatest.matchers.ShouldMatchers;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith;\n\nimport Statistics._\nimport scalala.tensor.mutable.{Matrix, Vector}\n\n@RunWith(classOf[JUnitRunner])\nclass StatisticsTest extends FunSuite with Checkers with ShouldMatchers {\n  test(\"corrcoef\") {\n    corrcoef(Vector(1,2,3), Vector(2,3,3.4)) should be (0.97072 plusOrMinus 1e-5);\n    assert(corrcoef(Vector[Double](), Vector[Double]()).isNaN);\n  }\n\n  test(\"kendall\") {\n    val a = Vector(2.5,2.5,2.5,2.5,5,6.5,6.5,10,10,10,10,10,14,14,14,16,17);\n    val b = Vector(1,1,1,1,2,1,1,2,1,1,1,1,1,1,2,2,2);\n    kendall(a,b) should be (0.40754 plusOrMinus 1e-5);\n\n    val x = Vector(1.5,1.5,3,4,6,6,6,8,9.5,9.5,11,12);\n    val y = Vector(2.5,2.5,7,4.5,1,4.5,6,11.5,11.5,8.5,8.5,10);\n    kendall(x,y) should be (0.55286 plusOrMinus 1e-5);\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/library/StorageTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala.library\n\nimport org.scalatest._\nimport org.scalatest.junit._\nimport org.scalatest.prop._\nimport org.scalatest.matchers.ShouldMatchers\nimport org.junit.runner.RunWith\nimport scalala.tensor.dense.DenseMatrix\nimport java.io.{ByteArrayInputStream, ByteArrayOutputStream}\n\n@RunWith(classOf[JUnitRunner])\nclass StorageTest extends FunSuite with Checkers with ShouldMatchers {\n\n  test(\"StoreTxtAndLoadTxt\") {\n    val os = new ByteArrayOutputStream\n\n    val m = DenseMatrix.randn(5,5)\n    Storage.storetxt(os, m)\n    val n = Storage.loadtxt(new ByteArrayInputStream(os.toByteArray))\n    m foreachPair ((idx,v) => n(idx) should be (v plusOrMinus 1e-15))\n\n    os.reset()\n    Storage.storetxt(os, m)\n    val o = Storage.loadtxt(new ByteArrayInputStream(os.toByteArray), skipRows=2)\n    o.numRows should be (m.numRows-2)\n    o foreachPair ((idx,v) => m(idx._1+2,idx._2) should be (v plusOrMinus 1e-15))\n\n    os.reset()\n    Storage.storetxt(os, m)\n    val p = Storage.loadtxt(new ByteArrayInputStream(os.toByteArray), columns=Seq(1,3))\n    p.numCols should be (2)\n    p foreachPair {\n      case ((row,0), v) => m(row,1) should be (v plusOrMinus 1e-15)\n      case ((row,1), v) => m(row,3) should be (v plusOrMinus 1e-15)\n      case _ => true should be (false) // signal failure\n    }\n\n    val is = new ByteArrayInputStream(\"1.0 2.0 #test\\n#foo\\n3.0 4.0\".getBytes)\n    val r = Storage.loadtxt(is)\n    r.numRows should be (2)\n    r.numCols should be (2)\n    r(0,0) should be (1.0)\n    r(0,1) should be (2.0)\n    r(1,0) should be (3.0)\n    r(1,1) should be (4.0)\n  }\n\n}\n"
  },
  {
    "path": "src/test/scala/scalala/operators/ArrayTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage operators;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\nimport Implicits._;\n\n@RunWith(classOf[JUnitRunner])\nclass ArrayTest extends FunSuite with Checkers {\n\n  def mk[V:ClassManifest](values : V*) =\n    Array[V](values :_*);\n\n  test(\"Negation\") {\n    val a = mk(1,2,3);\n    assert((-a).toList === List(-1,-2,-3));\n  }\n\n  test(\"Collection Ops\") {\n    val a = mk(1,2,3);\n    val b = mk(4,5,6);\n\n    assert((a + b).toList === List(5,7,9));\n    assert((a - b).toList === List(-3,-3,-3));\n    assert((a :* b).toList === List(4,10,18));\n    assert((b :/ a).toList === List(4,2,2));\n    assert((a :/ b.map(_.toDouble)).toList === List(0.25,0.4,0.5));\n    assert((b :% a).toList === List(0,1,0));\n  }\n\n  test(\"Scalar Ops\") {\n    val a = mk(1,2,3);\n\n    assert((a + 1).toList === List(2.0,3.0,4.0));\n    assert((a - 1).toList === List(0,1,2));\n    assert((a * 3.0).toList === List(3.0,6.0,9.0));\n    assert((a / 2.0).toList === List(0.5,1.0,1.5));\n    assert((a % 2).toList === List(1,0,1));\n  }\n  \n  test(\"Binary Ops\") {\n    val a = mk(0,-1,2);\n    val b = mk(0.0,0.0,3.0);\n    assert((a :&& b).toList === List(false,false,true));\n    assert((a :|| b).toList === List(false,true,true));\n    assert((a :^^ b).toList === List(false,true,false));\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/operators/SparseArrayTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage operators;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass SparseArrayTest extends FunSuite with Checkers {\n\n  import scalala.collection.sparse.{SparseArray,DefaultArrayValue};\n\n  def mk[V:ClassManifest:DefaultArrayValue](values : V*) =\n    SparseArray(values :_*);\n\n  test(\"Negation\") {\n    val a = mk(1,0,3);\n    assert((-a).toList === List(-1,0,-3));\n  }\n\n  test(\"Zeros\") {\n    val a = mk(1,0,3);\n    val b = mk(4,5,0);\n\n    assert((a :+ b).toList === List(5,5,3));\n    assert((b :+ a).toList === List(5,5,3));\n    assert((a :- b).toList === List(-3,-5,3));\n    assert((a :* b).toList === List(4,0,0));\n  }\n\n  test(\"Collection Ops\") {\n    val a = mk(1,2,3);\n    val b = mk(4,5,6);\n\n    assert((a :+ b).toList === List(5,7,9));\n    assert((a :- b).toList === List(-3,-3,-3));\n    assert((a :* b).toList === List(4,10,18));\n    assert((b :/ a).toList === List(4,2,2));\n    assert((a :/ b.map(_.toDouble)).toList === List(0.25,0.4,0.5));\n    assert((b :% a).toList === List(0,1,0));\n  }\n\n  test(\"Scalar Ops\") {\n    val a = mk(1,2,3);\n\n    assert((a :+ 1.0).toList === List(2.0,3.0,4.0));\n    assert((a :- 1).toList === List(0,1,2));\n    assert((a :* 3.0).toList === List(3.0,6.0,9.0));\n    assert((a :/ 2.0).toList === List(0.5,1.0,1.5));\n    assert((a :% 2).toList === List(1,0,1));\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/operators/TupleTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage operators;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\nimport Implicits._;\n\n@RunWith(classOf[JUnitRunner])\nclass TupleTest extends FunSuite with Checkers {\n\n  test(\"Neg\") {\n    assert(-(1,2.0,3f) === (-1, -2.0, -3f));\n  }\n\n  test(\"Add\") {\n    assert((1,2,3l) + (3.0,2,-1) === (4.0,4,2l));\n    assert((1,2,3,4) + 1 === (2,3,4,5));\n    assert(2f :+ (1,2.0,3,4,6) === (3f,4.0,5f,6f,8f));\n  }\n\n  test(\"Sub\") {\n    assert((1,2,3l) - (3.0,2,-1) === (-2.0,0,4l));\n    assert((1,2,3,4) - 1 === (0,1,2,3));\n    assert(7.0 :- (1,2,3,4) === (6.0,5.0,4.0,3.0));\n  }\n\n  test(\"Mul\") {\n    assert((1,2) :* (2,4) === (2,8));\n    assert((1,2,3,4) :* 2.0 === (2.0,4.0,6.0,8.0));\n    assert(0.5f :* (1,2,3,4) === (0.5f,1.0f,1.5f,2.0f));\n  }\n  \n  test(\"Div\") {\n    assert((4,2) :/ (2,2) === (2,1));\n    assert((1,2,3,4) :/ 2.0 === (0.5,1.0,1.5,2.0));\n    assert(2f :/ (1,2,4) === (2f,1f,0.5f));\n  }\n  \n  test(\"Mod\") {\n    assert((3,5) :% 2 === (1,1));\n  }\n  \n  test(\"Compare\") {\n    assert(((1,2,3) :<  (3,2,1)) === (true,false,false));\n    assert(((1,2,3) :<= (3,2,1)) === (true,true,false));\n    assert(((1,2,3) :>  (3,2,1)) === (false,false,true));\n    assert(((1,2,3) :>= (3,2,1)) === (false,true,true));\n    assert(((1,2,3) :== (3,2,1)) === (false,true,false));\n    assert(((1,2,3) :!= (3,2,1)) === (true,false,true));\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/operators/bundles/VectorSpaceTest.scala",
    "content": "package scalala\npackage operators\npackage bundles\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\nimport tensor.dense.{DenseVectorCol, DenseVector}\n\n// This test basically just makes sure things compile\n@RunWith(classOf[JUnitRunner])\nclass VectorSpaceTest extends FunSuite with Checkers {\n  type DVectorSpace[V] = MutableVectorSpace[Double,V];\n  def vsAdd[V:DVectorSpace](v1: V, v2: V) = {\n    val dv = implicitly[DVectorSpace[V]];\n    import dv._;\n    v1 + v2;\n  }\n  test(\"VectorSpace basically works\") {\n    VectorSpace.make[DenseVectorCol[Double],Double];\n    val r = vsAdd(DenseVector(1.,2.,3.),DenseVector(3.,4.,5.))\n    assert(r === DenseVector(4.,6.,8.));\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/scalar/ComplexTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.scalar;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass ComplexTest extends FunSuite with Checkers {\n\n  test(\"Add\") {\n    assert((1 + 2*i) + (2 + 3*i) === (3 + 5*i));\n  }\n\n  test(\"Sub\") {\n    assert((1 + 2*i) - (2 + 3*i) === (-1 - i));\n  }\n\n  test(\"Div\") {\n    assert((5 + 10*i) / (3 - 4*i) === (-1 + 2*i));\n  }\n\n  test(\"Mul\") {\n    assert((1 + 2*i) * (-3 + 6*i) === -15);\n    assert((1 + 5*i) * (-3 + 2*i) === (-13 - 13*i));\n  }\n\n  test(\"Neg\") {\n    assert(-(1 + 2*i) === (-1 - 2*i));\n  }\n\n  test(\"Abs/Conj\") {\n    assert((3 + 4*i).abs === 5);\n    val c = (1.7 + 2.1*i);\n    assert(c * c.conjugate === 7.3);\n  }\n\n  test(\"List[Complex].sum (test ComplexIsFractional)\") {\n    val x = List((5 + 7*i), (1 + 3*i), (13 + 17*i))\n    assert(x.sum === (19 + 27*i))\n  }\n\n  test(\"List[Complex].product (test ComplexIsFractional)\") {\n    val x = List((5 + 7*i), (1 + 3*i), (13 + 17*i))\n    assert(x.product === (-582 + 14*i))\n  }\n\n  test(\"List[Complex].sorted (test ComplexOrdering)\") {\n    val x = List((5 + 7*i), (1 + 3*i), (13 + 17*i))\n    assert(x.sorted === List((1 + 3*i), (5 + 7*i), (13 + 17*i)))\n  }\n\n  test(\"Only permit conversion to built-in numeric types when purely real.\") {\n    val a = 5 + 0*i  // should allow conversion\n    val b = 5 + 5*i  // should bork with an IllegalArgumentException\n\n    def toDouble[Complex](c: Complex)(implicit n: Numeric[Complex]): Double = \n      n.toDouble(c)\n    def toFloat[Complex](c: Complex)(implicit n: Numeric[Complex]): Float =\n      n.toFloat(c)\n    def toInt[Complex](c: Complex)(implicit n: Numeric[Complex]): Int =\n      n.toInt(c)\n    def toLong[Complex](c: Complex)(implicit n: Numeric[Complex]): Long =\n      n.toLong(c)\n\n    assert(toDouble(a) === 5)\n    assert(toFloat(a) === 5)\n    assert(toInt(a) === 5)\n    assert(toLong(a) === 5)\n    intercept[IllegalArgumentException] { toDouble(b) }\n    intercept[IllegalArgumentException] { toFloat(b) }\n    intercept[IllegalArgumentException] { toInt(b) }\n    intercept[IllegalArgumentException] { toLong(b) }\n  }\n\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/CRSTensor2Test.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.tensor;\n\n\nimport dense.{DenseVectorCol, DenseVector}\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\nimport domain._;\n\n@RunWith(classOf[JUnitRunner])\nclass CRSTensor2Test extends FunSuite with Checkers {\n  def typeOf[X](value : X)(implicit m : scala.reflect.Manifest[X]) =\n    m.toString;\n  def show[X](value : X)(implicit m : scala.reflect.Manifest[X]) = {\n    println(typeOf(value) + \":\");\n    println(value);\n    println();\n  }\n\n  test(\"Getting and setting\") {\n    val x = mutable.CRSTensor2[String,Int,Double,DenseVectorCol[Double]](DenseVector.zeros(3));\n    x(\"a\",1) = 3.0;\n    x(\"b\",2) = 7.75;\n    x(\"c\",2) = 8.0;\n\n    assert(x.valuesIterator.toSet === Set(3.0,8.0,7.75,0.0));\n  }\n\n  test(\"Slice rows\") {\n    val x = mutable.CRSTensor2[String,Int,Double,DenseVectorCol[Double]](DenseVector.zeros(3));\n    x(\"a\",::) := DenseVector(1.,2.,3.)\n\n    // require expected static type\n    val s1 : DenseVectorCol[Double] = x(\"a\",::);\n    assert(s1 === DenseVector(1.,2.,3.));\n\n    // write-through\n    s1(1) = 4;\n    assert(x(\"a\",1) === 4.0);\n\n  }\n\n  /*\n  test(\"Addition\") {\n    // require expected static type\n    val x = mutable.CRSTensor2[String,Int,Double,DenseVectorCol[Double]](DenseVector.zeros(3));\n    x(\"a\") := DenseVector(1.,2.,3.);\n      Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) + Counter2((\"a\",\"a\",3));\n    assert(v1 === Counter2((\"a\",\"a\",4),(\"b\",\"b\",2)));\n    \n    // require expected static type\n    val v2 : mutable.Counter2[String,Char,Int] =\n      Counter2((\"a\",'a',3)) + Counter2((\"a\",'a',1),(\"b\",'b',2));\n    assert(v2 === Counter2((\"a\",'a',4),(\"b\",'b',2)));\n  }\n  \n  test(\"AddInto\") {\n    val x = Counter2[String,String,Int]();\n    x += Counter2((\"a\",\"a\",1));\n    assert(x === Counter2((\"a\",\"a\",1)));\n    x += Counter2((\"a\",\"a\",2),(\"a\",\"b\",4));\n    assert(x === Counter2((\"a\",\"a\",3),(\"a\",\"b\",4)));\n  }\n\n  test(\"Subtraction\") {\n    assert(mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) - mutable.Counter2((\"a\",\"a\",3)) === Counter2((\"a\",\"a\",-2), (\"b\",\"b\",2)));\n    assert(mutable.Counter2((\"a\",\"a\",3)) - mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) === Counter2((\"a\",\"a\",2), (\"b\",\"b\",-2)));\n  }\n\n  test(\"Multiplication\") {\n    assert(mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) :* mutable.Counter2((\"a\",\"a\",3)) === Counter2((\"a\",\"a\",3)));\n    assert(mutable.Counter2((\"a\",\"a\",3)) :* mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) === Counter2((\"a\",\"a\",3)));\n  }\n  */\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/Counter2Test.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.tensor;\n\n\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\nimport domain._;\n\n@RunWith(classOf[JUnitRunner])\nclass Counter2Test extends FunSuite with Checkers {\n  def typeOf[X](value : X)(implicit m : scala.reflect.Manifest[X]) =\n    m.toString;\n  def show[X](value : X)(implicit m : scala.reflect.Manifest[X]) = {\n    println(typeOf(value) + \":\");\n    println(value);\n    println();\n  }\n\n  test(\"Getting and setting\") {\n    val x = mutable.Counter2[String,Int,Double]();\n    x(\"a\",1) = 3.0;\n    x(\"b\",2) = 7.75;\n    x(\"c\",2) = 8.0;\n\n    assert(x.valuesIterator.toSet === Set(3.0,8.0,7.75));\n  }\n\n  test(\"Transpose\") {\n    val x = mutable.Counter2[String,Int,Double]();\n    x((\"a\",1),(\"b\",2),(\"c\",2)) := List(3.0,7.75,8.0);\n\n    assert(x.t.valuesIterator.toSet === Set(3.0,0.0, 0.0, 0.0, 8.0,7.75));\n    assert(x.t.t === x);\n    assert(x.t.t eq x);\n\n    x.t(2,\"a\") = 1;\n    assert(x(\"a\",2) === 1);\n  }\n\n  test(\"Slice table\") {\n    val x= mutable.Counter2[String,Int,Double]();\n    x((\"a\",1),(\"b\",2),(\"c\",2)) := List(3.0,7.75,8.0);\n\n    val table = x(List(\"a\",\"b\",\"c\"),List(1,2));\n\n    assert(table.domain === TableDomain(3,2));\n\n    table(1,0) = 5;\n    assert(x(\"b\",1) === 5);\n  }\n\n  test(\"Slice rows and columns\") {\n    val x = mutable.Counter2[String,Int,Double]();\n    x((\"a\",1),(\"b\",2),(\"c\",2)) := List(3.0,7.75,8.0);\n\n    // require expected static type\n    val s1 : mutable.Counter[Int,Double] = x(\"a\",::);\n    assert(s1.toMap === Map(1->3.0));\n\n    // write-through\n    s1(1) = 4;\n    assert(x(\"a\",1) === 4.0);\n\n    // require expected static type\n    val s2 : mutable.Counter[String,Double] = x(::,2);\n    assert(s2.toMap === Map(\"a\" -> 0.0, \"b\" -> 7.75, \"c\" -> 8.0));\n    \n    // write-through\n    s2(\"a\") = 1;\n    assert(x(\"a\",2) === 1.0);\n  }\n\n  test(\"Addition\") {\n    // require expected static type\n    val v1 : mutable.Counter2[String,String,Int] =\n      Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) + Counter2((\"a\",\"a\",3));\n    assert(v1 === Counter2((\"a\",\"a\",4),(\"b\",\"b\",2)));\n    \n    // require expected static type\n    val v2 : mutable.Counter2[String,Char,Int] =\n      Counter2((\"a\",'a',3)) + Counter2((\"a\",'a',1),(\"b\",'b',2));\n    assert(v2 === Counter2((\"a\",'a',4),(\"b\",'b',2)));\n  }\n  \n  test(\"AddInto\") {\n    val x = Counter2[String,String,Int]();\n    x += Counter2((\"a\",\"a\",1));\n    assert(x === Counter2((\"a\",\"a\",1)));\n    x += Counter2((\"a\",\"a\",2),(\"a\",\"b\",4));\n    assert(x === Counter2((\"a\",\"a\",3),(\"a\",\"b\",4)));\n  }\n\n  test(\"Subtraction\") {\n    assert(mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) - mutable.Counter2((\"a\",\"a\",3)) === Counter2((\"a\",\"a\",-2), (\"b\",\"b\",2)));\n    assert(mutable.Counter2((\"a\",\"a\",3)) - mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) === Counter2((\"a\",\"a\",2), (\"b\",\"b\",-2)));\n  }\n\n  test(\"Multiplication\") {\n    assert(mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) :* mutable.Counter2((\"a\",\"a\",3)) === Counter2((\"a\",\"a\",3)));\n    assert(mutable.Counter2((\"a\",\"a\",3)) :* mutable.Counter2((\"a\",\"a\",1),(\"b\",\"b\",2)) === Counter2((\"a\",\"a\",3)));\n  }\n  \n  test(\"Shaped Multiplication\") {\n    assert(Counter2((0,'a',1),(1,'a',2),(1,'b',3)) * Counter2(('a',0,1),('b',0,2)) ===\n      Counter2((0,0,1),(1,0,8)));\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/CounterTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.tensor;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass CounterTest extends FunSuite with Checkers {\n  val TOLERANCE = 1e-4;\n  def assertClose(a : Double, b : Double) =\n    assert(math.abs(a - b) < TOLERANCE);\n\n  test(\"Addition\") {\n    assert(mutable.Counter(\"a\"->1,\"b\"->2) + mutable.Counter(\"a\"->3) === Counter(\"a\"->4,\"b\"->2));\n    assert(mutable.Counter(\"a\"->3) + mutable.Counter(\"a\"->1,\"b\"->2) === Counter(\"a\"->4,\"b\"->2));\n  }\n\n  test(\"Subtraction\") {\n    assert(mutable.Counter(\"a\"->1,\"b\"->2) - mutable.Counter(\"a\"->3) === Counter(\"a\" -> -2, \"b\" -> 2));\n    assert(mutable.Counter(\"a\"->3) - mutable.Counter(\"a\"->1,\"b\"->2) === Counter(\"a\" -> 2, \"b\" -> -2));\n  }\n\n  test(\"Multiplication\") {\n    assert(mutable.Counter(\"a\"->1,\"b\"->2) :* mutable.Counter(\"a\"->3) === Counter(\"a\"->3));\n    assert(mutable.Counter(\"a\"->3) :* mutable.Counter(\"a\"->1,\"b\"->2) === Counter(\"a\"->3));\n  }\n\n  test(\"MulInner\") {\n    val a = mutable.Counter(1->0.56390,2->0.36231,3->0.14601,4->0.60294,5->0.14535);\n    val b = mutable.Counter(1->0.15951,2->0.83671,3->0.56002,4->0.57797,5->0.54450);\n    assertClose(a dot b, .90249);\n  }\n\n  test(\"Zero + non zero is nonzero\") {\n    val a = mutable.Counter[Int,Double](1->0.0)\n    val b = mutable.Counter(1->0.15951);\n    assert(a + b === b, (a + b).toString + \" not equal \" + b)\n  }\n\n  test(\"Mean\") {\n    assert(Counter(0->0,1->1,2->2).mean === 1.0);\n    assert(Counter(0->0.0,1->3.0).mean === 1.5);\n    assert(Counter(0->3l).mean === 3.0);\n  }\n\n  test(\"assignment checks both domains\") {\n    val a = Counter[Int,Int]()\n    val b = Counter[Int,Int](3->4)\n    a := b\n    assert(a === b)\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/DiagonalMatrixTest.scala",
    "content": "package scalala.tensor\n\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\nimport dense.{DenseVector, DenseMatrix}\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\nimport scalala.library.LinearAlgebra.diag;\n\n@RunWith(classOf[JUnitRunner])\nclass DiagonalMatrixTest extends FunSuite with Checkers {\n\n\n  test(\"Multiply\") {\n    val a = DenseMatrix((1, 2, 3),(4, 5, 6),(7,8,9));\n    val c = diag(DenseVector(6,2,3));\n    val ac :DenseMatrix[Int] = a * c; // check types;\n    assert(a * c === DenseMatrix( (6,4,9),(24,10,18),(42,16,27)));\n  }\n\n\n\n\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/Tensor2Test.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.tensor;\n\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\nimport domain._;\n\n@RunWith(classOf[JUnitRunner])\nclass Tensor2Test extends FunSuite with Checkers {\n  def mkTensor2() = {\n    val domain = Domain2(SetDomain(Set(\"a\",\"b\",\"c\")), SetDomain(Set(1,2)));\n    mutable.Tensor2[String,Int,Double](domain);\n  }\n\n  def typeOf[X](value : X)(implicit m : scala.reflect.Manifest[X]) =\n    m.toString;\n  def show[X](value : X)(implicit m : scala.reflect.Manifest[X]) = {\n    println(typeOf(value) + \":\");\n    println(value);\n    println();\n  }\n\n  test(\"Getting and setting\") {\n    val x = mkTensor2();\n    x(\"a\",1) = 3.0;\n    x(\"b\",2) = 7.75;\n    x(\"c\",2) = 8.0;\n\n    assert(x.valuesIterator.toList === List(3.0,0,0,7.75,0,8.0));\n  }\n\n  test(\"Transpose\") {\n    val x = mkTensor2();\n    x((\"a\",1),(\"b\",2),(\"c\",2)) := List(3.0,7.75,8.0);\n\n    assert(x.t.valuesIterator.toList === List(3.0,0,0,0,7.75,8.0));\n    assert(x.t.t === x);\n    assert(x.t.t eq x);\n\n    x.t(2,\"a\") = 1;\n    assert(x(\"a\",2) === 1);\n  }\n\n  test(\"Slice table\") {\n    val x= mkTensor2();\n    x((\"a\",1),(\"b\",2),(\"c\",2)) := List(3.0,7.75,8.0);\n\n    val table = x(List(\"a\",\"b\",\"c\"),List(1,2));\n\n    assert(table.domain === TableDomain(3,2));\n\n    table(1,0) = 5;\n    assert(x(\"b\",1) === 5);\n  }\n\n  test(\"Slice rows and columns\") {\n    val x= mkTensor2();\n    x((\"a\",1),(\"b\",2),(\"c\",2)) := List(3.0,7.75,8.0);\n\n    assert(x(\"a\", ::).isInstanceOf[Tensor1[_,_]]);\n    assert(x(\"a\", ::).toMap === Map(1->3.0, 2->0))\n\n    assert(x(::, 2).isInstanceOf[Tensor1[_,_]]);\n    assert(x(::, 2).toMap === Map(\"a\" -> 0.0, \"b\" -> 7.75, \"c\" -> 8.0))\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/TensorTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala.tensor;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass TensorTest extends FunSuite with Checkers {\n  def mkMapTensor() =\n    mutable.Tensor[String,Int](domain.SetDomain(Set(\"a\",\"b\",\"c\")));\n\n  test(\"Get and set values\") {\n    val x = mkMapTensor();\n    assert(x(\"a\") === 0);\n    assert(x(\"b\") === 0);\n    assert(x(\"c\") === 0);\n    x(\"a\") = 5; x(\"b\") = 7; x(\"c\") = 2;\n    assert(x(\"a\") === 5);\n    assert(x(\"b\") === 7);\n    assert(x(\"c\") === 2);\n  }\n\n  test(\"Slicing to a sequence\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(1,2,3);\n    assert(x(\"a\") === 1);\n    assert(x(\"b\") === 2);\n    assert(x(\"c\") === 3);\n\n    assert(x(\"c\",\"a\",\"b\",\"b\",\"a\").valuesIterator.toList === List(3,1,2,2,1));\n  }\n\n  test(\"Slicing to new keys\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(1,2,3);\n    val y = x(0->\"a\", 1->\"b\", 2->\"c\");\n    assert(y(0) === x(\"a\"));\n    assert(y(1) === x(\"b\"));\n    assert(y(2) === x(\"c\"));\n  }\n\n  test(\"Map values\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(1,2,3);\n    assert(x.mapValues(_ % 2 == 0).valuesIterator.toList === List(false,true,false));\n  }\n\n  test(\"Filter values\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(1,2,3);\n    x(x.findAll(_ >= 2)) := 0;\n    assert(x.valuesIterator.toList === List(1,0,0));\n  }\n\n  test(\"Find\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(1,2,3);\n    assert(x.findAll(_ >= 2).toList === List(\"b\",\"c\"));\n  }\n\n  test(\"Overlapping slice assignments\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(1,2,3);\n    x(\"a\",\"b\") := x(\"b\",\"c\");\n    assert(x.valuesIterator.toList === List(2,3,3));\n  }\n\n  test(\"Sorting\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(5,7,3);\n    \n    assert(x.argsort.toList === List(\"c\",\"a\",\"b\"));\n\n    assert(x.sorted.valuesIterator.toList === List(3,5,7));\n  }\n\n  test(\"Min/Max\") {\n    val x = mkMapTensor();\n    x(\"a\",\"b\",\"c\") := List(5,7,3);\n    assert(x.min === 3);\n    assert(x.max === 7);\n    assert(x.argmin === \"c\");\n    assert(x.argmax === \"b\");\n  }\n}\n\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/dense/DenseMatrixTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage dense;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\n\n@RunWith(classOf[JUnitRunner])\nclass DenseMatrixTest extends FunSuite with Checkers {\n\n  test(\"Slicing\") {\n    val m = DenseMatrix((0,1,2),\n                        (3,4,5));\n    \n    // slice sub-matrix\n    val s1 : mutable.Matrix[Int] = m(0 to 1, 1 to 2);\n    assert(s1 === DenseMatrix((1,2),(4,5)));\n    s1 += 1;\n    assert(m === DenseMatrix((0,2,3),(3,5,6)));\n    \n    // slice row\n    val s2 : DenseVectorRow[Int] = m(0, ::);\n    assert(s2 === DenseVector(0,2,3));\n    s2 *= 2;\n    assert(m === DenseMatrix((0,4,6),(3,5,6)));\n    \n    // slice column\n    val s3 : DenseVectorCol[Int] = m(::, 1);\n    assert(s3 === DenseVector(4,5));\n    s3 -= 1;\n    assert(m === DenseMatrix((0,3,6),(3,4,6)));\n    \n    // slice rows\n    val s4 : mutable.Matrix[Int] = m(1 to 1, ::);\n    assert(s4 === DenseMatrix((3,4,6)));\n    \n    // slice columns\n    val s5 : mutable.Matrix[Int] = m(::, 1 to 2);\n    assert(s5 === DenseMatrix((3,6),(4,6)));\n    \n    // slice part of a row\n    val s6a : DenseVectorRow[Int] = m(0, 1 to 2);\n    s6a += 2;\n    val s6b : mutable.VectorRow[Int] = m(0,IndexedSeq(2,1));\n    s6b -= 1;\n    assert(m === DenseMatrix((0,4,7),(3,4,6)));\n    \n    // slice part of a column\n    val s7a : DenseVectorCol[Int] = m(0 to 1, 0);\n    s7a += 2;\n    val s7b : mutable.VectorCol[Int] = m(IndexedSeq(1,0),0);\n    s7b += 1;\n    assert(m === DenseMatrix((3,4,7),(6,4,6)));\n  }\n\n  test(\"Transpose\") {\n    val m = DenseMatrix((1,2,3),(4,5,6));\n\n    // check that the double transpose gives us back the original\n    assert(m.t.t eq m);\n\n    // check static type and write-through\n    val t : mutable.Matrix[Int] = m.t;\n    assert(t === DenseMatrix((1,4),(2,5),(3,6)));\n    t(0,1) = 0;\n    assert(m === DenseMatrix((1,2,3),(0,5,6)));\n  }\n\n  test(\"Sliced Transpose\") {\n    val m = DenseMatrix((0, 1, 2),\n      (3, 4, 5));\n\n    // slice sub-matrix\n    val s1: mutable.Matrix[Int] = m(0 to 1, 1 to 2);\n    assert(s1 === DenseMatrix((1, 2), (4, 5)));\n\n    val t1: mutable.Matrix[Int] = s1.t\n    assert(t1 === DenseMatrix((1, 4), (2, 5)));\n  }\n\n  test(\"Min/Max\") {\n    val m = DenseMatrix((1,0,0),(2,3,-1));\n    assert(m.argmin === (1,2));\n    assert(m.argmax === (1,1));\n    assert(m.min === -1);\n    assert(m.max === 3);\n  }\n\n  test(\"MapValues\") {\n    val a : DenseMatrix[Int] = DenseMatrix((1,0,0),(2,3,-1));\n    \n    val b1 : DenseMatrix[Int] = a.mapValues(_ + 1);\n    assert(b1 === DenseMatrix((2,1,1),(3,4,0)));\n    \n    val b2 : DenseMatrix[Double] = a.mapValues(_ + 1.0);\n    assert(b2 === DenseMatrix((2.0,1.0,1.0),(3.0,4.0,0.0)));\n  }\n\n  test(\"Map\") {\n    val a : DenseMatrix[Int] = DenseMatrix((1,0,0),(2,3,-1));\n    \n    val b1 : DenseMatrix[Int] = a.mapTriples((i,j,v) => i + v);\n    assert(b1 === DenseMatrix((1,0,0),(3,4,0)));\n    \n    val b2 : DenseMatrix[Double] = a.mapTriples((i,j,v) => j + v.toDouble);\n    assert(b2 === DenseMatrix((1.0,1.0,2.0),(2.0,4.0,1.0)));\n  }\n\n  test(\"Triples\") {\n    val a : DenseMatrix[Int] = DenseMatrix((1,0,0),(2,3,-1));\n    \n    var s = 0;\n    \n    // foreach\n    s = 0;\n    for ((i,j,v) <- a.triples) s += v;\n    assert(s === a.sum);\n    \n    // filter\n    s = 0;\n    for ((i,j,v) <- a.triples; if i % 2 == 0 || j % 2 == 0) s += v;\n    assert(s === 1+2-1);\n    \n//    // map\n//    val b1 : DenseMatrix[Double] = for ((i,j,v) <- a) yield v * 2.0;\n//    assert(b1 === DenseMatrix((2.0,0.0,0.0),(4.0,6.0,-2.0)));\n//    \n//    // map with filter\n//    val b2 : DenseMatrix[Int] = for ((i,j,v) <- a; if j == 0) yield v * 2;\n//    assert(b2 === DenseMatrix((2,0,0),(4,0,0)));\n  }\n    \n\n  test(\"horzcat\") {\n    val a : DenseMatrix[Int] = DenseMatrix((1,0,0),(2,3,-1));\n    val result: DenseMatrix[Int] = DenseMatrix((1,0,0,1,0, 0),(2,3,-1,2,3,-1));\n    assert(DenseMatrix.horzcat(a,a) === result);\n  }\n\n  test(\"vertcat\") {\n    val a : DenseMatrix[Int] = DenseMatrix((1,0,0),(2,3,-1));\n    val result: DenseMatrix[Int] = DenseMatrix((1,0,0),(2,3,-1),(1,0,0),(2,3,-1));\n    assert(DenseMatrix.vertcat(a,a) === result);\n  }\n\n\n  test(\"Multiply\") {\n    val a = DenseMatrix((1, 2, 3),(4, 5, 6));\n    val b = DenseMatrix((7, -2, 8),(-3, -3, 1),(12, 0, 5));\n    val c = DenseVector(6,2,3);\n    assert(a * b === DenseMatrix((37, -8, 25), (85, -23, 67)));\n    assert(a * c === DenseVector(19,52));\n    \n    // should be dense\n    val x : DenseMatrix[Int] = a * a.t;\n    assert(x === DenseMatrix((14,32),(32,77)));\n    \n    // should be dense\n    val y : DenseMatrix[Int] = a.t * a;\n    assert(y === DenseMatrix((17,22,27),(22,29,36),(27,36,45)));\n    \n    // should promote\n    val z : DenseMatrix[Double] = b * (b + 1.0);\n    assert(z === DenseMatrix((164,5,107),(-5,10,-27),(161,-7,138)));\n  }\n\n  test(\"Trace\") {\n    assert(DenseMatrix((1,2,3),(4,5,6)).trace === 1 + 5);\n    assert(DenseMatrix((1,2),(3,4),(5,6)).trace == 1 + 4);\n    assert(DenseMatrix((1,2,3),(4,5,6),(7,8,9)).trace === 1 + 5 + 9);\n  }\n\n  test(\"Reshape\") {\n    val m : DenseMatrix[Int] = DenseMatrix((1,2,3),(4,5,6));\n    val r : DenseMatrix[Int] = m.reshape(3,2);\n    assert(m.data eq r.data);\n    assert(r.numRows === 3);\n    assert(r.numCols === 2);\n    assert(r === DenseMatrix((1,5),(4,3),(2,6)));\n  }\n\n  test(\"Solve\") {\n    // square solve\n    val r1 : DenseMatrix[Double] = DenseMatrix((1.0,3.0),(2.0,0.0)) \\ DenseMatrix((1.0,2.0),(3.0,4.0));\n    assert(r1 === DenseMatrix((1.5, 2.0), (-1.0/6, 0.0)));\n\n    // matrix-vector solve\n    val r2 : DenseVector[Double] = DenseMatrix((1.0,3.0,4.0),(2.0,0.0,6.0)) \\ DenseVector(1.0,3.0);\n    assert(r2 === DenseVector(0.1813186813186811, -0.3131868131868131, 0.43956043956043944));\n\n    // wide matrix solve\n    val r3 : DenseMatrix[Double] = DenseMatrix((1.0,3.0,4.0),(2.0,0.0,6.0)) \\ DenseMatrix((1.0,2.0),(3.0,4.0));\n    assert(r3 === DenseMatrix((0.1813186813186811,   0.2197802197802196),\n                              (-0.3131868131868131, -0.1978021978021977),\n                              (0.43956043956043944,  0.5934065934065933)));\n\n    // tall matrix solve\n    val r4 : DenseMatrix[Double] = DenseMatrix((1.0,3.0),(2.0,0.0),(4.0,6.0)) \\ DenseMatrix((1.0,4.0),(2.0,5.0),(3.0,6.0));\n    assert(r4 === DenseMatrix((0.9166666666666667,    1.9166666666666672),\n                             (-0.08333333333333352, -0.08333333333333436)));\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/dense/DenseVectorConstructorTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\n\npackage scalala.tensor.dense\n\nimport org.scalatest._\nimport org.scalatest.matchers.ShouldMatchers\nimport org.scalatest.junit._\nimport org.junit.runner.RunWith\nimport scalala.tensor.domain.IndexDomain\nimport scalala.library.random.MersenneTwisterFast\n\n@RunWith(classOf[JUnitRunner])\nclass DenseVectorConstructorTest extends FunSuite with ShouldMatchers {\n\n  test(\"DenseVectorRow\") {\n    val vd: DenseVectorRow[Double] = DenseVectorRow(1.0, 2.0, 3.0)\n    vd.length should equal (3)\n    (vd.values zip (1 to 3)) foreach { case (a,b) => a should equal (b) }\n\n    val vf: DenseVectorRow[Float] = DenseVectorRow(Array(1.0f, 2.0f, 3.0f))\n    vf.length should equal (3)\n    (vf.values zip (1 to 3)) foreach { case (a,b) => a should equal (b) }\n\n    val vdomi: DenseVectorRow[Int] = DenseVectorRow[Int](IndexDomain(10))\n    vdomi.length should equal (10)\n    vdomi.values foreach (_ should equal (0))\n\n    val vdf: DenseVectorRow[Double] = DenseVectorRow.fill(23)(3.0)\n    vdf.length should equal (23)\n    vdf.values foreach (_ should equal (3.0))\n\n    val vdz: DenseVectorRow[Double] = DenseVectorRow.zeros[Double](42)\n    vdz.length should equal (42)\n    vdz.values foreach (_ should equal (0))\n\n    // TODO: Insert test for zeros and non-primitive types. But -- are there\n    // currently any non-primitive scalars at all?\n\n    val vbo: DenseVectorRow[Boolean] = DenseVectorRow.ones[Boolean](8)\n    vbo.length should equal (8)\n    vbo.values foreach (_ should equal (true))\n\n    val vit: DenseVectorRow[Int] = DenseVectorRow.tabulate[Int](3)(_ * 3)\n    vit.length should equal (3)\n    (vit.values zip (0 to 6 by 3)) foreach { case (a,b) => a should equal (b) }\n\n    val vir: DenseVectorRow[Int] = DenseVectorRow.range(0, 100, 10)\n    vir.length should equal(10)\n    (vir.values zip (0 to 100 by 10)) foreach { case (a,b) => a should equal (b) }\n\n    val mt = new MersenneTwisterFast(0l)\n\n    val vdr: DenseVectorRow[Double] = DenseVectorRow.rand(5, mt)\n    (vdr.values zip Seq(0.548, 0.715, 0.602, 0.544, 0.423)) foreach\n      { case (a,b) => a should be (b plusOrMinus 1e-3) }\n\n    val vdrn: DenseVectorRow[Double] = DenseVectorRow.randn(5, mt)\n    (vdrn.values zip Seq(1.969, -0.842, -0.505, 1.266, 1.080)) foreach\n      { case (a,b) => a should be (b plusOrMinus 1e-3) }\n\n    val viri: DenseVectorRow[Int] = DenseVectorRow.randi(1888, 5, mt)\n    (viri.values zip Seq(242, 140, 262, 644, 388)) foreach\n      { case (a,b) => a should equal (b) }\n\n    val vhc: DenseVectorRow[Double] = DenseVectorRow.horzcat[Double](vd, vd, vd)\n    (vhc.values zip Seq(1,2,3,1,2,3,1,2,3)) foreach\n      { case (a,b) => a should equal (b) }\n\n    val vvc: DenseMatrix[Int] =\n      DenseVectorRow.vertcat[Int](DenseVectorRow(1,2,3),\n                                  DenseVectorRow(4,5,6),\n                                  DenseVectorRow(7,8,9))\n    vvc foreachPair { case ((i,j), v) => v should equal (i*3+j+1) }\n\n    evaluating {\n        // Incompatible lengths\n        DenseVectorRow.vertcat(DenseVectorRow(1,2), DenseVectorRow(4,5,6))\n    } should produce [IllegalArgumentException]\n  }\n\n  test(\"DenseVectorCol\") {\n    val vd: DenseVectorCol[Double] = DenseVectorCol(1.0, 2.0, 3.0)\n    vd.length should equal (3)\n    (vd.values zip (1 to 3)) foreach { case (a,b) => a should equal (b) }\n\n    val vf: DenseVectorCol[Float] = DenseVectorCol(Array(1.0f, 2.0f, 3.0f))\n    vf.length should equal (3)\n    (vf.values zip (1 to 3)) foreach { case (a,b) => a should equal (b) }\n\n    val vdomi: DenseVectorCol[Int] = DenseVectorCol[Int](IndexDomain(10))\n    vdomi.length should equal (10)\n    vdomi.values foreach (_ should equal (0))\n\n    val vdf: DenseVectorCol[Double] = DenseVectorCol.fill(23)(3.0)\n    vdf.length should equal (23)\n    vdf.values foreach (_ should equal (3.0))\n\n    val vdz: DenseVectorCol[Double] = DenseVectorCol.zeros[Double](42)\n    vdz.length should equal (42)\n    vdz.values foreach (_ should equal (0))\n\n    // TODO: Insert test for zeros and non-primitive types. But -- are there\n    // currently any non-primitive scalars at all?\n\n    val vbo: DenseVectorCol[Boolean] = DenseVectorCol.ones[Boolean](8)\n    vbo.length should equal (8)\n    vbo.values foreach (_ should equal (true))\n\n    val vit: DenseVectorCol[Int] = DenseVectorCol.tabulate[Int](3)(_ * 3)\n    vit.length should equal (3)\n    (vit.values zip (0 to 6 by 3)) foreach { case (a,b) => a should equal (b) }\n\n    val vir: DenseVectorCol[Int] = DenseVectorCol.range(0, 100, 10)\n    vir.length should equal(10)\n    (vir.values zip (0 to 100 by 10)) foreach { case (a,b) => a should equal (b) }\n\n    val mt = new MersenneTwisterFast(0l)\n\n    val vdr: DenseVectorCol[Double] = DenseVectorCol.rand(5, mt)\n    (vdr.values zip Seq(0.548, 0.715, 0.602, 0.544, 0.423)) foreach\n      { case (a,b) => a should be (b plusOrMinus 1e-3) }\n\n    val vdrn: DenseVectorCol[Double] = DenseVectorCol.randn(5, mt)\n    (vdrn.values zip Seq(1.969, -0.842, -0.505, 1.266, 1.080)) foreach\n      { case (a,b) => a should be (b plusOrMinus 1e-3) }\n\n    val viri: DenseVectorCol[Int] = DenseVectorCol.randi(1888, 5, mt)\n    (viri.values zip Seq(242, 140, 262, 644, 388)) foreach\n      { case (a,b) => a should equal (b) }\n\n    val vhc: DenseVectorCol[Double] = DenseVectorCol.vertcat[Double](vd, vd, vd)\n    (vhc.values zip Seq(1,2,3,1,2,3,1,2,3)) foreach\n      { case (a,b) => a should equal (b) }\n\n    val vvc: DenseMatrix[Int] =\n      DenseVectorCol.horzcat[Int](DenseVectorCol(1,4,7),\n                                  DenseVectorCol(2,5,8),\n                                  DenseVectorCol(3,6,9))\n    vvc foreachPair { case ((i,j), v) => v should equal (i*3+j+1) }\n\n    evaluating {\n        // Incompatible lengths\n        DenseVectorCol.horzcat(DenseVectorCol(1,2), DenseVectorCol(4,5,6))\n    } should produce [IllegalArgumentException]\n  }\n\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/dense/DenseVectorTest.scala",
    "content": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA\n */\npackage scalala;\npackage tensor;\npackage dense;\n\nimport org.scalacheck._\nimport org.scalatest._;\nimport org.scalatest.junit._;\nimport org.scalatest.prop._;\nimport org.junit.runner.RunWith\nimport mutable.Tensor;\n\n@RunWith(classOf[JUnitRunner])\nclass DenseVectorTest extends FunSuite with Checkers {\n\n  val TOLERANCE = 1e-4;\n  def assertClose(a : Double, b : Double) =\n    assert(math.abs(a - b) < TOLERANCE);\n\n  test(\"Min/Max\") {\n    val v = DenseVector(2,0,3,2,-1);\n    assert(v.argmin === 4);\n    assert(v.argmax === 2);\n    assert(v.min === -1);\n    assert(v.max === 3);\n  }\n\n  test(\"Mean\") {\n    assert(DenseVector(0,1,2).mean === 1.0);\n    assert(DenseVector(0.0,3.0).mean === 1.5);\n    assert(DenseVector(3l).mean === 3.0);\n  }\n\n  test(\"Norm\") {\n    val v = DenseVector(-0.4326,-1.6656,0.1253,0.2877,-1.1465);\n    assertClose(v.norm(1), 3.6577);\n    assertClose(v.norm(2), 2.0915);\n    assertClose(v.norm(3), 1.8405);\n    assertClose(v.norm(4), 1.7541);\n    assertClose(v.norm(5), 1.7146);\n    assertClose(v.norm(6), 1.6940);\n    assertClose(v.norm(Double.PositiveInfinity), 1.6656);\n  }\n\n  test(\"MulInner\") {\n    val a = DenseVector(0.56390,0.36231,0.14601,0.60294,0.14535);\n    val b = DenseVector(0.15951,0.83671,0.56002,0.57797,0.54450);\n    assertClose(a dot b, .90249);\n    assertClose(a.t * b, .90249);\n  }\n\n  test(\"MulOuter\") {\n    val a = DenseVector(1, 2, 3);\n    val b = DenseVector(6, -4, 8);\n\n    // assert result is a dense matrix\n    val m : DenseMatrix[Int] = a * b.t;\n    assert(m === DenseMatrix((6,-4,8),(12,-8,16),(18,-12,24)));\n  }\n\n  test(\"MulMatrix\") {\n    val x = DenseVector(1,2).t;\n    val m = DenseMatrix((1,2,1),(2,7,8));\n\n    // assert return type is statically a dense row\n    val r : DenseVectorRow[Int] = x * m;\n    assert(r === DenseVector(5, 16, 17));\n  }\n\n  test(\"Slice\") {\n    val x = DenseVector.zeros[Int](5);\n\n    // check that the slice is a vector and mutable\n    val y : mutable.Vector[Int] = x(0 to 2);\n    y :+= 1;\n\n    val z : mutable.Vector[Int] = x(1 to 3);\n    z :+= 1;\n\n    assert(x === DenseVector(1,2,2,1,0));\n\n    assert(x(0 until 5) === x);\n    assert(try { x(0 to 5); false; } catch { case _ => true });\n  }\n\n  test(\"Slice and Transpose\") {\n    val x = DenseVector[Int](1, 2, 3, 4, 5);\n\n    val s: DenseVectorCol[Int] = x(2 to 3);\n\n    assert(s === DenseVector(3, 4));\n\n    val t: mutable.Vector[Int] = s.t;\n\n    assert(t === DenseVector(3, 4).t);\n\n    val emptySlice = x(2 until 2)\n    assert(emptySlice === DenseVector[Int]())\n  }\n\n  // https://github.com/scalala/Scalala/pull/19\n  test(\"Supertype mutator\") {\n    val a = DenseVector(13, 42);\n    val b = DenseVector(7, 42);\n    val expected = DenseVector(6, 0);\n  \n    val direct = a - b;\n    assert(direct === expected);\n  \n    (a: Tensor[Int, Int]) :-= b;\n    assert(a === expected);\n  }\n\n  test(\"Transpose\") {\n    val x : DenseVectorCol[Int] = DenseVector(1,2,3);\n\n    // test static type and write-through of transpose\n    val y : DenseVectorRow[Int] = x.t;\n    y(0) = 0;\n    assert(x === DenseVector(0,2,3));\n  }\n\n  test(\"MapValues\") {\n    val a : DenseVector[Int] = DenseVector(1,2,3,4,5);\n    val m : DenseVector[Int] = a.mapValues(_ + 1);\n    assert(m === DenseVector(2,3,4,5,6));\n  }\n\n  test(\"ForComprehensions\") {\n    val a : DenseVectorCol[Int] = DenseVector(1,2,3,4,5);\n\n    var s = 0;\n\n    // foreach\n    s = 0;\n    for (v <- a) s += v;\n    assert(s === a.sum);\n\n    // filter\n    s = 0;\n    for (v <- a; if v < 3) s += v;\n    assert(s === 1+2);\n\n    // map\n    val b1 : DenseVectorCol[Double] = for (v <- a) yield v * 2.0;\n    assert(b1 === DenseVector(2.0,4.0,6.0,8.0,10.0));\n\n    // map with filter\n    val b2 : DenseVectorCol[Int] = for (v <- a; if v < 3) yield v * 2;\n    assert(b2 === DenseVector(2.0,4.0));\n\n    // transpose map with filter\n    val b3 : DenseVectorRow[Int] = for (v <- a.t; if v < 3) yield v * 3;\n    assert(b3 === DenseVector(3,6).t);\n  }\n\n  test(\"Tabulate\") {\n    val m = DenseVector.tabulate(5)(i => i + 1);\n    assert(m === DenseVector(1,2,3,4,5));\n  }\n\n  test(\"VertCat\") {\n    val a1 = DenseVector(1,2,3);\n    val a2 = DenseVector(2,3,4);\n    val res = DenseVector(1,2,3,2,3,4);\n    assert(DenseVector.vertcat(a1,a2) === res);\n  }\n\n  test(\"Negation\") {\n    val a1 = DenseVector(1,2,3);\n    assert(-a1 == DenseVector(-1,-2,-3))\n\n  }\n}\n"
  },
  {
    "path": "src/test/scala/scalala/tensor/sparse/SparseVectorTest.scala",
    "content": "package scalala.tensor.sparse\n\nimport org.scalatest._\nimport org.scalatest.matchers.ShouldMatchers\nimport org.scalatest.junit._\nimport org.junit.runner.RunWith\nimport scalala.tensor.dense.DenseVector\n\n/**\n * \n * @author dlwh\n */\n@RunWith(classOf[JUnitRunner])\nclass SparseVectorTest extends FunSuite with ShouldMatchers  {\n\n  val TOLERANCE = 1e-4;\n  def assertClose(a : Double, b : Double) =\n    assert(math.abs(a - b) < TOLERANCE, a + \" vs. \" +  b);\n\n  test(\"MulInner\") {\n    val a = SparseVector(0.56390,0.36231,0.14601,0.60294,0.14535);\n    val b = SparseVector(0.15951,0.83671,0.56002,0.57797,0.54450);\n    val bd = DenseVector(0.15951,0.83671,0.56002,0.57797,0.54450);\n    val bdSplit = DenseVector(0., 0.15951, 0., 0.83671,0., 0.56002, 0., 0.57797, 0., 0.54450);\n    val bdd = bdSplit(1 to 9 by 2)\n    assertClose(a dot b, .90249);\n    assertClose(a dot bd, .90249);\n    assertClose(bd dot a, .90249);\n    assertClose(bdd dot a, .90249);\n    assertClose(a.t * b, .90249);\n  }\n\n  test(\"Subtraction\") {\n    val a = SparseVector(0.56390,0.36231,0.14601,0.60294,0.14535);\n    val ad = DenseVector(0.56390,0.36231,0.14601,0.60294,0.14535);\n    val b = SparseVector(0.15951,0.83671,0.56002,0.57797,0.54450);\n    val bd = DenseVector(0.15951,0.83671,0.56002,0.57797,0.54450);\n    val bdd = bd - ad\n    b -= a\n    bd -= a\n    assertClose(b.norm(2), bd.norm(2))\n    assertClose(bdd.norm(2), bd.norm(2))\n  }\n\n}"
  }
]