Full Code of scalala/Scalala for AI

master 6206a4601322 cached
173 files
1.0 MB
333.7k tokens
24 symbols
1 requests
Download .txt
Showing preview only (1,110K chars total). Download the full file or copy to clipboard to get everything.
Repository: scalala/Scalala
Branch: master
Commit: 6206a4601322
Files: 173
Total size: 1.0 MB

Directory structure:
gitextract_e_sqcedj/

├── .gitignore
├── LICENSE
├── README
├── build.sbt
├── project/
│   ├── build.properties
│   └── plugins.sbt
├── sbt
└── src/
    ├── main/
    │   ├── java/
    │   │   └── scalala/
    │   │       └── library/
    │   │           └── random/
    │   │               └── MersenneTwisterFast.java
    │   ├── resources/
    │   │   └── scalala.scala
    │   └── scala/
    │       └── scalala/
    │           ├── ScalalaConsole.scala
    │           ├── collection/
    │           │   └── sparse/
    │           │       └── SparseArray.scala
    │           ├── generic/
    │           │   ├── collection/
    │           │   │   ├── CanAppendColumns.scala
    │           │   │   ├── CanBuildTensorForBinaryOp.scala
    │           │   │   ├── CanBuildTensorFrom.scala
    │           │   │   ├── CanCopy.scala
    │           │   │   ├── CanCreateZerosLike.scala
    │           │   │   ├── CanFilterValues.scala
    │           │   │   ├── CanGetActiveValues.scala
    │           │   │   ├── CanGetDouble.scala
    │           │   │   ├── CanGetValue.scala
    │           │   │   ├── CanJoin.scala
    │           │   │   ├── CanMapKeyValuePairs.scala
    │           │   │   ├── CanMapValues.scala
    │           │   │   ├── CanSliceMatrix.scala
    │           │   │   ├── CanSliceTensor.scala
    │           │   │   ├── CanSliceVector.scala
    │           │   │   ├── CanTranspose.scala
    │           │   │   ├── CanView.scala
    │           │   │   ├── CanViewAsTensor1.scala
    │           │   │   ├── CanViewAsTensor2.scala
    │           │   │   ├── CanViewAsVector.scala
    │           │   │   └── CanZipMapValues.scala
    │           │   └── math/
    │           │       ├── CanAbs.scala
    │           │       ├── CanExp.scala
    │           │       ├── CanLog.scala
    │           │       ├── CanMean.scala
    │           │       ├── CanNorm.scala
    │           │       ├── CanSoftmax.scala
    │           │       ├── CanSqrt.scala
    │           │       └── CanVariance.scala
    │           ├── library/
    │           │   ├── Library.scala
    │           │   ├── LinearAlgebra.scala
    │           │   ├── Numerics.scala
    │           │   ├── Plotting.scala
    │           │   ├── Random.scala
    │           │   ├── Statistics.scala
    │           │   ├── Storage.scala
    │           │   └── plotting/
    │           │       ├── Dataset.scala
    │           │       ├── ExportGraphics.scala
    │           │       ├── Figure.scala
    │           │       ├── Figures.scala
    │           │       ├── HistogramBins.scala
    │           │       ├── PaintScale.scala
    │           │       ├── PaintScaleFactory.scala
    │           │       └── XYPlot.scala
    │           ├── operators/
    │           │   ├── BinaryOp.scala
    │           │   ├── BinaryOpRegistry.scala
    │           │   ├── BinaryUpdateOp.scala
    │           │   ├── CanCast.scala
    │           │   ├── OpType.scala
    │           │   ├── Ops.scala
    │           │   ├── Shape.scala
    │           │   ├── TupleOps.scala
    │           │   ├── UnaryOp.scala
    │           │   ├── ValuesMonadic.scala
    │           │   ├── bundles/
    │           │   │   └── VectorSpace.scala
    │           │   └── codegen/
    │           │       ├── BinaryOpGenerator.scala
    │           │       ├── DynamicCompiler.scala
    │           │       └── GeneratedBinaryOp.scala
    │           ├── scalar/
    │           │   ├── Complex.scala
    │           │   ├── RichScalar.scala
    │           │   ├── Scalar.scala
    │           │   ├── ScalarDecimal.scala
    │           │   └── package.scala
    │           └── tensor/
    │               ├── CRSTensor2.scala
    │               ├── Counter.scala
    │               ├── Counter2.scala
    │               ├── DiagonalMatrix.scala
    │               ├── DomainFunction.scala
    │               ├── LiteralRow.scala
    │               ├── Matrix.scala
    │               ├── MatrixSingularException.scala
    │               ├── MatrixTranspose.scala
    │               ├── SelectAll.scala
    │               ├── Tensor.scala
    │               ├── Tensor1.scala
    │               ├── Tensor1Col.scala
    │               ├── Tensor1Proxy.scala
    │               ├── Tensor1Row.scala
    │               ├── Tensor1Slice.scala
    │               ├── Tensor2.scala
    │               ├── Tensor2Transpose.scala
    │               ├── TensorN.scala
    │               ├── TensorProxy.scala
    │               ├── TensorSlice.scala
    │               ├── TensorView.scala
    │               ├── Vector.scala
    │               ├── VectorCol.scala
    │               ├── VectorProxy.scala
    │               ├── VectorRow.scala
    │               ├── VectorSlice.scala
    │               ├── dense/
    │               │   ├── ArrayArrayMatrix.scala
    │               │   ├── DenseArrayTensor.scala
    │               │   ├── DenseMatrix.scala
    │               │   └── DenseVector.scala
    │               ├── domain/
    │               │   ├── CanBuildDomain2.scala
    │               │   ├── CanGetDomain.scala
    │               │   ├── Domain.scala
    │               │   ├── Domain1.scala
    │               │   ├── Domain2.scala
    │               │   ├── DomainN.scala
    │               │   ├── IndexDomain.scala
    │               │   ├── IterableDomain.scala
    │               │   ├── SetDomain.scala
    │               │   ├── TableDomain.scala
    │               │   └── UnionDomain.scala
    │               ├── generic/
    │               │   ├── TensorBuilder.scala
    │               │   ├── TensorKeysMonadic.scala
    │               │   ├── TensorNonZeroKeysMonadic.scala
    │               │   ├── TensorNonZeroMonadic.scala
    │               │   ├── TensorNonZeroPairsMonadic.scala
    │               │   ├── TensorNonZeroTriplesMonadic.scala
    │               │   ├── TensorNonZeroValuesMonadic.scala
    │               │   ├── TensorPairsMonadic.scala
    │               │   ├── TensorTriplesMonadic.scala
    │               │   └── TensorValuesMonadic.scala
    │               ├── mutable/
    │               │   ├── CRSTensor2.scala
    │               │   ├── Counter.scala
    │               │   ├── Counter2.scala
    │               │   ├── Matrix.scala
    │               │   ├── MatrixTranspose.scala
    │               │   ├── Tensor.scala
    │               │   ├── Tensor1.scala
    │               │   ├── Tensor1Col.scala
    │               │   ├── Tensor1Row.scala
    │               │   ├── Tensor1Slice.scala
    │               │   ├── Tensor2.scala
    │               │   ├── Tensor2Transpose.scala
    │               │   ├── TensorProxy.scala
    │               │   ├── TensorSlice.scala
    │               │   ├── Vector.scala
    │               │   ├── VectorCol.scala
    │               │   ├── VectorRow.scala
    │               │   └── VectorSlice.scala
    │               ├── package.scala
    │               └── sparse/
    │                   ├── SparseArrayTensor.scala
    │                   └── SparseVector.scala
    └── test/
        └── scala/
            └── scalala/
                ├── collection/
                │   └── sparse/
                │       └── SparseArrayTest.scala
                ├── generic/
                │   ├── CanAssignIntoTest.scala
                │   └── collection/
                │       ├── CanGetDoubleTest.scala
                │       ├── CanGetValueTest.scala
                │       └── CanMapValuesTest.scala
                ├── library/
                │   ├── LibraryTest.scala
                │   ├── LinearAlgebraTest.scala
                │   ├── NumericsTest.scala
                │   ├── RandomTest.scala
                │   ├── StatisticsTest.scala
                │   └── StorageTest.scala
                ├── operators/
                │   ├── ArrayTest.scala
                │   ├── SparseArrayTest.scala
                │   ├── TupleTest.scala
                │   └── bundles/
                │       └── VectorSpaceTest.scala
                ├── scalar/
                │   └── ComplexTest.scala
                └── tensor/
                    ├── CRSTensor2Test.scala
                    ├── Counter2Test.scala
                    ├── CounterTest.scala
                    ├── DiagonalMatrixTest.scala
                    ├── Tensor2Test.scala
                    ├── TensorTest.scala
                    ├── dense/
                    │   ├── DenseMatrixTest.scala
                    │   ├── DenseVectorConstructorTest.scala
                    │   └── DenseVectorTest.scala
                    └── sparse/
                        └── SparseVectorTest.scala

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
*~
.idea/
.idea_modules/
.manager/
workspace.xml
bin/
docs/
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/


================================================
FILE: LICENSE
================================================
                  GNU LESSER GENERAL PUBLIC LICENSE
                       Version 2.1, February 1999

 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

[This is the first released version of the Lesser GPL.  It also counts
 as the successor of the GNU Library Public License, version 2, hence
 the version number 2.1.]

                            Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.

  This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it.  You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.

  When we speak of free software, we are referring to freedom of use,
not price.  Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.

  To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights.  These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.

  For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you.  You must make sure that they, too, receive or can get the source
code.  If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it.  And you must show them these terms so they know their rights.

  We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.

  To protect each distributor, we want to make it very clear that
there is no warranty for the free library.  Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.

  Finally, software patents pose a constant threat to the existence of
any free program.  We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder.  Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.

  Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License.  This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License.  We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.

  When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library.  The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom.  The Lesser General
Public License permits more lax criteria for linking other code with
the library.

  We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License.  It also provides other free software developers Less
of an advantage over competing non-free programs.  These disadvantages
are the reason we use the ordinary General Public License for many
libraries.  However, the Lesser license provides advantages in certain
special circumstances.

  For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard.  To achieve this, non-free programs must be
allowed to use the library.  A more frequent case is that a free
library does the same job as widely used non-free libraries.  In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.

  In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software.  For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.

  Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.

  The precise terms and conditions for copying, distribution and
modification follow.  Pay close attention to the difference between a
"work based on the library" and a "work that uses the library".  The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.

                  GNU LESSER GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".

  A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.

  The "Library", below, refers to any such software library or work
which has been distributed under these terms.  A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language.  (Hereinafter, translation is
included without limitation in the term "modification".)

  "Source code" for a work means the preferred form of the work for
making modifications to it.  For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.

  Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it).  Whether that is true depends on what the Library does
and what the program that uses the Library does.

  1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.

  You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

  2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) The modified work must itself be a software library.

    b) You must cause the files modified to carry prominent notices
    stating that you changed the files and the date of any change.

    c) You must cause the whole of the work to be licensed at no
    charge to all third parties under the terms of this License.

    d) If a facility in the modified Library refers to a function or a
    table of data to be supplied by an application program that uses
    the facility, other than as an argument passed when the facility
    is invoked, then you must make a good faith effort to ensure that,
    in the event an application does not supply such function or
    table, the facility still operates, and performs whatever part of
    its purpose remains meaningful.

    (For example, a function in a library to compute square roots has
    a purpose that is entirely well-defined independent of the
    application.  Therefore, Subsection 2d requires that any
    application-supplied function or table used by this function must
    be optional: if the application does not supply it, the square
    root function must still compute square roots.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.

In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library.  To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License.  (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.)  Do not make any other change in
these notices.

  Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.

  This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.

  4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.

  If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.

  5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library".  Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.

  However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library".  The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.

  When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library.  The
threshold for this to be true is not precisely defined by law.

  If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work.  (Executables containing this object code plus portions of the
Library will still fall under Section 6.)

  Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

  6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

  You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License.  You must supply a copy of this License.  If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License.  Also, you must do one
of these things:

    a) Accompany the work with the complete corresponding
    machine-readable source code for the Library including whatever
    changes were used in the work (which must be distributed under
    Sections 1 and 2 above); and, if the work is an executable linked
    with the Library, with the complete machine-readable "work that
    uses the Library", as object code and/or source code, so that the
    user can modify the Library and then relink to produce a modified
    executable containing the modified Library.  (It is understood
    that the user who changes the contents of definitions files in the
    Library will not necessarily be able to recompile the application
    to use the modified definitions.)

    b) Use a suitable shared library mechanism for linking with the
    Library.  A suitable mechanism is one that (1) uses at run time a
    copy of the library already present on the user's computer system,
    rather than copying library functions into the executable, and (2)
    will operate properly with a modified version of the library, if
    the user installs one, as long as the modified version is
    interface-compatible with the version that the work was made with.

    c) Accompany the work with a written offer, valid for at
    least three years, to give the same user the materials
    specified in Subsection 6a, above, for a charge no more
    than the cost of performing this distribution.

    d) If distribution of the work is made by offering access to copy
    from a designated place, offer equivalent access to copy the above
    specified materials from the same place.

    e) Verify that the user has already received a copy of these
    materials or that you have already sent this user a copy.

  For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it.  However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.

  It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system.  Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

  7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

    a) Accompany the combined library with a copy of the same work
    based on the Library, uncombined with any other library
    facilities.  This must be distributed under the terms of the
    Sections above.

    b) Give prominent notice with the combined library of the fact
    that part of it is a work based on the Library, and explaining
    where to find the accompanying uncombined form of the same work.

  8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License.  Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License.  However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.

  9. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Library or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.

  10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.

  11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all.  For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.

If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded.  In such case, this License incorporates the limitation as if
written in the body of this License.

  13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number.  If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

  14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission.  For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this.  Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.

                            NO WARRANTY

  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

                     END OF TERMS AND CONDITIONS

           How to Apply These Terms to Your New Libraries

  If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change.  You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

  To apply these terms, attach the following notices to the library.  It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

    <one line to give the library's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  library `Frob' (a library for tweaking knobs) written by James Random Hacker.

  <signature of Ty Coon>, 1 April 1990
  Ty Coon, President of Vice

That's all there is to it!



================================================
FILE: README
================================================
Scalala is a high performance numeric linear algebra library for Scala,
with rich Matlab-like operators on vectors and matrices; a library of
numerical routines; support for plotting.

This software is released under the LGPL.  See LICENSE for details. 

(c) 2008- | Daniel Ramage | dramage | http://cs.stanford.edu/~dramage 

With contributions from:
  David Hall <dlwh>
  Jason Zaugg <retronym>
  Alexander Lehmann <afwlehmann>
  Jonathan Merritt <lancelet>
  aerskine
  And others (email me if you've contributed code and aren't listed)

Building upon and/or borrowing from solid libraries:
  JFreeChart  http://www.jfree.org/jfreechart/
  Netlib      http://code.google.com/p/netlib-java/
  MTJ         http://code.google.com/p/matrix-toolkits-java/ 
  iText       http://www.itextpdf.com/

The source currently lives on github.  You can download a copy:

  git clone https://github.com/scalala/Scalala.git

Scalala is built with sbt, which is included in the repository or
can be downloaded from https://github.com/harrah/xsbt/wiki.

Run sbt (./sbt) and invoke one or more of the following targets:
  update      -- Downloads scalala's dependencies
  compile     -- Builds the library
  test        -- Runs the unit tests
  doc         -- Builds scaladoc for the public API
  proguard    -- Builds a distributable jar
  gen-idea    -- Generate an IntelliJ IDEA project

For project maintainers, the project can be deployed with:
  publish

To run an interactive console, either do so through sbt (console or
console-quick) or run sbt's proguard target, and then:
  java -jar target/scala_2.8.1/scalala*.min.jar

Documentation is available here:
  https://github.com/scalala/Scalala/wiki/Scalala

And informal support is available here:
  http://groups.google.com/group/scalala



================================================
FILE: build.sbt
================================================

name := "scalala"

version := "1.0.0.RC3-SNAPSHOT"

organization := "org.scalala"

scalaVersion := "2.9.2"

crossScalaVersions := Seq("2.8.2", "2.9.1", "2.9.2")

resolvers ++= Seq(
  "ScalaNLP Maven2" at "http://repo.scalanlp.org/repo",
  "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/"
)

libraryDependencies ++= Seq(
  "com.googlecode.netlib-java" % "netlib-java" % "0.9.3",
  "jfree" % "jcommon" % "1.0.16",
  "jfree" % "jfreechart" % "1.0.13",
  "org.apache.xmlgraphics" % "xmlgraphics-commons" % "1.3.1", // for eps gen
  // "org.apache.xmlgraphics" % "batik-dom" % "1.7",    // for svg gen
  // "org.apache.xmlgraphics" % "batik-svggen" % "1.7", // for svg gen
  "com.lowagie" % "itext" % "2.1.5" intransitive(),  // for pdf gen
  "junit" % "junit" % "4.5" % "test"
)

libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>
  deps :+ ("org.scala-lang" % "scala-compiler" % sv)
}

libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>
  val Scala210 = """2\.10\.0.*""".r
  sv match {
    case "2.9.1" | "2.9.2" | Scala210() =>
      deps :+ ("jline" % "jline" % "0.9.94") // ("org.scala-lang" % "jline" % "2.9.1")
    case x if x.startsWith("2.8") =>
      deps :+ ("jline" % "jline" % "0.9.94")
    case x       => error("Unsupported Scala version " + x)
  }
}

libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>
  val Scala210 = """2\.10\.0.*""".r
  sv match {
    case Scala210() => deps
    case "2.9.1" | "2.9.2" =>
      (deps :+ ("org.scalatest" % "scalatest" % "1.4.RC2" % "test")
            :+ ("org.scala-tools.testing" % "scalacheck_2.9.1" % "1.9" % "test"))
    case x if x.startsWith("2.8") =>
      (deps :+ ("org.scalatest" % "scalatest" % "1.3" % "test")
            :+ ("org.scala-tools.testing" % "scalacheck_2.8.1" % "1.8" % "test"))
    case x  => error("Unsupported Scala version " + x)
  }
}

publishTo <<= (version) { version: String =>
  val nexus = "http://nexus.scala-tools.org/content/repositories/"
  if (version.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "snapshots/")
  else                                   Some("releases"  at nexus + "releases/")
}

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

javacOptions ++= Seq("-source", "1.5", "-target", "1.5")

scalacOptions ++= Seq("-no-specialization","-deprecation","-target:jvm-1.5")

initialCommands := scala.io.Source.fromFile("src/main/resources/scalala.scala").getLines.mkString("\n")

mainClass in (Compile,packageBin) := Some("scalala.ScalalaConsole")

javaOptions += "-Xmx2g"

seq(ProguardPlugin.proguardSettings :_*)

proguardOptions ++= Seq (
  "-keep class scalala.** { *; }",
  "-keep class org.jfree.** { *; }",
  keepMain("scalala.ScalalaConsole$"),
  keepMain("scala.tools.nsc.MainGenericRunner"),
  "-dontoptimize",
  "-dontobfuscate",
  keepLimitedSerializability,
  keepAllScala,
  "-keep class ch.epfl.** { *; }",
  "-keep interface scala.ScalaObject"
)

// seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)



================================================
FILE: project/build.properties
================================================
sbt.version=0.11.3

================================================
FILE: project/plugins.sbt
================================================

resolvers += "Proguard plugin repo" at "http://siasia.github.com/maven2"

libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-proguard-plugin" % ("0.11.2-0.1.1"))

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0")


================================================
FILE: sbt
================================================
#!/usr/bin/env bash
#
# A more capable sbt runner, coincidentally also called sbt.
# Author: Paul Phillips <paulp@typesafe.com>

# todo - make this dynamic
declare -r sbt_release_version=0.11.3
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT

unset sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
unset scala_version java_home sbt_explicit_version
unset verbose debug quiet

build_props_sbt () {
  if [[ -f project/build.properties ]]; then
    versionLine=$(grep ^sbt.version project/build.properties)
    versionString=${versionLine##sbt.version=}
    echo "$versionString"
  fi
}

update_build_props_sbt () {
  local ver="$1"
  local old=$(build_props_sbt)

  if [[ $ver == $old ]]; then
    return
  elif [[ -f project/build.properties ]]; then
    perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties
    grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties

    echo !!!
    echo !!! Updated file project/build.properties setting sbt.version to: $ver
    echo !!! Previous value was: $old
    echo !!!
  fi
}

sbt_version () {
  if [[ -n $sbt_explicit_version ]]; then
    echo $sbt_explicit_version
  else
    local v=$(build_props_sbt)
    if [[ -n $v ]]; then
      echo $v
    else
      echo $sbt_release_version
    fi
  fi
}

echoerr () {
  echo 1>&2 "$@"
}
vlog () {
  [[ $verbose || $debug ]] && echoerr "$@"
}
dlog () {
  [[ $debug ]] && echoerr "$@"
}

# this seems to cover the bases on OSX, and someone will
# have to tell me about the others.
get_script_path () {
  local path="$1"
  [[ -L "$path" ]] || { echo "$path" ; return; }

  local target=$(readlink "$path")
  if [[ "${target:0:1}" == "/" ]]; then
    echo "$target"
  else
    echo "$(dirname $path)/$target"
  fi
}

# a ham-fisted attempt to move some memory settings in concert
# so they need not be dicked around with individually.
get_mem_opts () {
  local mem=${1:-1536}
  local perm=$(( $mem / 4 ))
  (( $perm > 256 )) || perm=256
  (( $perm < 1024 )) || perm=1024
  local codecache=$(( $perm / 2 ))
  
  echo "-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m"
}

die() {
  echo "Aborting: $@"
  exit 1
}

make_url () {
  groupid="$1"
  category="$2"
  version="$3"
  
  echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
}

declare -r default_jvm_opts="-Dfile.encoding=UTF8"
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled"
declare -r default_sbt_mem=1536
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
declare -r sbt_opts_file=".sbtopts"
declare -r jvm_opts_file=".jvmopts"
declare -r latest_28="2.8.2"
declare -r latest_29="2.9.1"
declare -r latest_210="2.10.0-SNAPSHOT"

declare -r script_path=$(get_script_path "$BASH_SOURCE")
declare -r script_dir="$(dirname $script_path)"
declare -r script_name="$(basename $script_path)"

# some non-read-onlies set with defaults
declare java_cmd=java
declare sbt_launch_dir="$script_dir/.lib"
declare sbt_mem=$default_sbt_mem

# pull -J and -D options to give to java.
declare -a residual_args
declare -a java_args
declare -a scalac_args
declare -a sbt_commands

build_props_scala () {
  if [[ -f project/build.properties ]]; then
    versionLine=$(grep ^build.scala.versions project/build.properties)
    versionString=${versionLine##build.scala.versions=}
    echo ${versionString%% .*}
  fi
}

execRunner () {
  # print the arguments one to a line, quoting any containing spaces
  [[ $verbose || $debug ]] && echo "# Executing command line:" && {
    for arg; do
      if printf "%s\n" "$arg" | grep -q ' '; then
        printf "\"%s\"\n" "$arg"
      else
        printf "%s\n" "$arg"
      fi
    done
    echo ""
  }

  exec "$@"
}

sbt_groupid () {
  case $(sbt_version) in
        0.7.*) echo org.scala-tools.sbt ;;
       0.10.*) echo org.scala-tools.sbt ;;
    0.11.[12]) echo org.scala-tools.sbt ;;
            *) echo org.scala-sbt ;;
  esac
}

sbt_artifactory_list () {
  local version0=$(sbt_version)
  local version=${version0%-SNAPSHOT}
  local url="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/"
  dlog "Looking for snapshot list at: $url "
  
  curl -s --list-only "$url" | \
    grep -F $version | \
    perl -e 'print reverse <>' | \
    perl -pe 's#^<a href="([^"/]+).*#$1#;'
}

make_release_url () {
  make_url $(sbt_groupid) releases $(sbt_version)
}

# argument is e.g. 0.13.0-SNAPSHOT
# finds the actual version (with the build id) at artifactory
make_snapshot_url () {
  for ver in $(sbt_artifactory_list); do
    local url=$(make_url $(sbt_groupid) snapshots $ver)
    dlog "Testing $url"
    curl -s --head "$url" >/dev/null
    dlog "curl returned: $?"
    echo "$url"
    return
  done
}

jar_url () {
  case $(sbt_version) in
             0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
        *-SNAPSHOT) make_snapshot_url ;;
                 *) make_release_url ;;
  esac
}

jar_file () {
  echo "$sbt_launch_dir/$1/sbt-launch.jar"
}

download_url () {
  local url="$1"
  local jar="$2"
  
  echo "Downloading sbt launcher $(sbt_version):"
  echo "  From  $url"
  echo "    To  $jar"

  mkdir -p $(dirname "$jar") && {
    if which curl >/dev/null; then
      curl --fail --silent "$url" --output "$jar"
    elif which wget >/dev/null; then
      wget --quiet -O "$jar" "$url"
    fi
  } && [[ -f "$jar" ]]
}

acquire_sbt_jar () {
  sbt_url="$(jar_url)"
  sbt_jar="$(jar_file $(sbt_version))"

  [[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
}

usage () {
  cat <<EOM
Usage: $script_name [options]

  -h | -help         print this message
  -v | -verbose      this runner is chattier
  -d | -debug        set sbt log level to Debug
  -q | -quiet        set sbt log level to Error
  -no-colors         disable ANSI color codes
  -sbt-create        start sbt even if current directory contains no sbt project
  -sbt-dir   <path>  path to global settings/plugins directory (default: ~/.sbt/<version>)
  -sbt-boot  <path>  path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
  -ivy       <path>  path to local Ivy repository (default: ~/.ivy2)
  -mem    <integer>  set memory options (default: $sbt_mem, which is
                       $(get_mem_opts $sbt_mem) )
  -no-share          use all local caches; no sharing
  -offline           put sbt in offline mode
  -jvm-debug <port>  Turn on JVM debugging, open at the given port.
  -batch             Disable interactive mode

  # sbt version (default: from project/build.properties if present, else latest release)
  !!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
  !!! contains an sbt.version property is to update the file on disk.  That's what this does.
  -sbt-version  <version>   use the specified version of sbt 
  -sbt-jar      <path>      use the specified jar as the sbt launcher
  -sbt-snapshot             use a snapshot version of sbt
  -sbt-launch-dir <path>    directory to hold sbt launchers (default: $sbt_launch_dir)

  # scala version (default: as chosen by sbt)
  -28                       use $latest_28
  -29                       use $latest_29
  -210                      use $latest_210
  -scala-home <path>        use the scala build at the specified directory
  -scala-version <version>  use the specified version of scala

  # java version (default: java from PATH, currently $(java -version |& grep version))
  -java-home <path>         alternate JAVA_HOME

  # jvm options and output control
  JAVA_OPTS     environment variable holding jvm args, if unset uses "$default_jvm_opts"
  SBT_OPTS      environment variable holding jvm args, if unset uses "$default_sbt_opts"
  .jvmopts      if file is in sbt root, it is prepended to the args given to the jvm
  .sbtopts      if file is in sbt root, it is prepended to the args given to **sbt**
  -Dkey=val     pass -Dkey=val directly to the jvm
  -J-X          pass option -X directly to the jvm (-J is stripped)
  -S-X          add -X to sbt's scalacOptions (-J is stripped)

In the case of duplicated or conflicting options, the order above
shows precedence: JAVA_OPTS lowest, command line options highest.
EOM
}

addJava () {
  dlog "[addJava] arg = '$1'"
  java_args=( "${java_args[@]}" "$1" )
}
addSbt () {
  dlog "[addSbt] arg = '$1'"
  sbt_commands=( "${sbt_commands[@]}" "$1" )
}
addScalac () {
  dlog "[addScalac] arg = '$1'"
  scalac_args=( "${scalac_args[@]}" "$1" )
}
addResidual () {
  dlog "[residual] arg = '$1'"
  residual_args=( "${residual_args[@]}" "$1" )
}
addResolver () {
  addSbt "set resolvers in ThisBuild += $1"
}
addDebugger () {
  addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
}
get_jvm_opts () {
  # echo "${JAVA_OPTS:-$default_jvm_opts}"
  # echo "${SBT_OPTS:-$default_sbt_opts}"

  [[ -f "$jvm_opts_file" ]] && cat "$jvm_opts_file"
}

process_args ()
{
  require_arg () {
    local type="$1"
    local opt="$2"
    local arg="$3"
    
    if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
      die "$opt requires <$type> argument"
    fi
  }
  while [[ $# -gt 0 ]]; do
    case "$1" in
       -h|-help) usage; exit 1 ;;
    -v|-verbose) verbose=1 && shift ;;
      -d|-debug) debug=1 && shift ;;
      -q|-quiet) quiet=1 && shift ;;

           -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
           -mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;;
     -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
      -no-share) addJava "$noshare_opts" && shift ;;
      -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
       -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
     -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
       -offline) addSbt "set offline := true" && shift ;;
     -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
         -batch) exec </dev/null && shift ;;

    -sbt-create) sbt_create=true && shift ;;
  -sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
       -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
   -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
 -scala-version) require_arg version "$1" "$2" && addSbt "set scalaVersion := \"$2\"" && shift 2 ;;
    -scala-home) require_arg path "$1" "$2" && addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))" && shift 2 ;;
     -java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;

            -D*) addJava "$1" && shift ;;
            -J*) addJava "${1:2}" && shift ;;
            -S*) addScalac "${1:2}" && shift ;;
            -28) addSbt "++ $latest_28" && shift ;;
            -29) addSbt "++ $latest_29" && shift ;;
           -210) addSbt "++ $latest_210" && shift ;;

              *) addResidual "$1" && shift ;;
    esac
  done
  
  [[ $debug ]] && {
    case $(sbt_version) in
     0.7.*) addSbt "debug" ;; 
         *) addSbt "set logLevel in Global := Level.Debug" ;;
    esac
  }
  [[ $quiet ]] && {
    case $(sbt_version) in
     0.7.*) ;; 
         *) addSbt "set logLevel in Global := Level.Error" ;;
    esac
  }
}

# if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner
[[ -f "$sbt_opts_file" ]] && {
  sbtargs=()
  while IFS= read -r arg; do
    sbtargs=( "${sbtargs[@]}" "$arg" )
  done <"$sbt_opts_file"

  set -- "${sbtargs[@]}" "$@"
}

# process the combined args, then reset "$@" to the residuals
process_args "$@"
set -- "${residual_args[@]}"
argumentCount=$#

# set scalacOptions if we were given any -S opts
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""

# Update build.properties no disk to set explicit version - sbt gives us no choice
[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
echo "Detected sbt version $(sbt_version)"

[[ -n "$scala_version" ]] && echo "Overriding scala version to $scala_version"

# no args - alert them there's stuff in here
(( $argumentCount > 0 )) || echo "Starting $script_name: invoke with -help for other options"

# verify this is an sbt dir or -create was given
[[ -f ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
  cat <<EOM
$(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run:
  $0 -sbt-create

EOM
  exit 1
}

# pick up completion if present; todo
[[ -f .sbt_completion.sh ]] && source .sbt_completion.sh

# no jar? download it.
[[ -f "$sbt_jar" ]] || acquire_sbt_jar || {
  # still no jar? uh-oh.
  echo "Download failed. Obtain the jar manually and place it at $sbt_jar"
  exit 1
}

[[ -n "$sbt_dir" ]] || {
  sbt_dir=~/.sbt/$(sbt_version)
  addJava "-Dsbt.global.base=$sbt_dir"
  echo "Using $sbt_dir as sbt dir, -sbt-dir to override."
}

# since sbt 0.7 doesn't understand iflast
(( ${#residual_args[@]} == 0 )) && residual_args=( "shell" )

# run sbt
execRunner "$java_cmd" \
  $(get_mem_opts $sbt_mem) \
  $(get_jvm_opts) \
  ${java_args[@]} \
  -jar "$sbt_jar" \
  "${sbt_commands[@]}" \
  "${residual_args[@]}"

================================================
FILE: src/main/java/scalala/library/random/MersenneTwisterFast.java
================================================
package scalala.library.random;
import java.io.*;
import java.util.*;

/**
 * <h3>MersenneTwister and MersenneTwisterFast</h3>
 * <p><b>Version 13</b>, based on version MT199937(99/10/29)
 * of the Mersenne Twister algorithm found at
 * <a href="http://www.math.keio.ac.jp/matumoto/emt.html">
 * The Mersenne Twister Home Page</a>, with the initialization
 * improved using the new 2002/1/26 initialization algorithm
 * By Sean Luke, October 2004.
 *
 * <p><b>MersenneTwister</b> is a drop-in subclass replacement
 * for java.util.Random.  It is properly synchronized and
 * can be used in a multithreaded environment.  On modern VMs such
 * as HotSpot, it is approximately 1/3 slower than java.util.Random.
 *
 * <p><b>MersenneTwisterFast</b> is not a subclass of java.util.Random.  It has
 * the same public methods as Random does, however, and it is
 * algorithmically identical to MersenneTwister.  MersenneTwisterFast
 * has hard-code inlined all of its methods directly, and made all of them
 * final (well, the ones of consequence anyway).  Further, these
 * methods are <i>not</i> synchronized, so the same MersenneTwisterFast
 * instance cannot be shared by multiple threads.  But all this helps
 * MersenneTwisterFast achieve well over twice the speed of MersenneTwister.
 * java.util.Random is about 1/3 slower than MersenneTwisterFast.
 *
 * <h3>About the Mersenne Twister</h3>
 * <p>This is a Java version of the C-program for MT19937: Integer version.
 * The MT19937 algorithm was created by Makoto Matsumoto and Takuji Nishimura,
 * who ask: "When you use this, send an email to: matumoto@math.keio.ac.jp
 * with an appropriate reference to your work".  Indicate that this
 * is a translation of their algorithm into Java.
 *
 * <p><b>Reference. </b>
 * Makato Matsumoto and Takuji Nishimura,
 * "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform
 * Pseudo-Random Number Generator",
 * <i>ACM Transactions on Modeling and. Computer Simulation,</i>
 * Vol. 8, No. 1, January 1998, pp 3--30.
 *
 * <h3>About this Version</h3>
 *
 * <p><b>Changes Since V12:</b> clone() method added.
 *
 * <p><b>Changes Since V11:</b> stateEquals(...) method added.  MersenneTwisterFast
 * is equal to other MersenneTwisterFasts with identical state; likewise
 * MersenneTwister is equal to other MersenneTwister with identical state.
 * This isn't equals(...) because that requires a contract of immutability
 * to compare by value.
 *
 * <p><b>Changes Since V10:</b> A documentation error suggested that
 * setSeed(int[]) required an int[] array 624 long.  In fact, the array
 * can be any non-zero length.  The new version also checks for this fact.
 *
 * <p><b>Changes Since V9:</b> readState(stream) and writeState(stream)
 * provided.
 *
 * <p><b>Changes Since V8:</b> setSeed(int) was only using the first 28 bits
 * of the seed; it should have been 32 bits.  For small-number seeds the
 * behavior is identical.
 *
 * <p><b>Changes Since V7:</b> A documentation error in MersenneTwisterFast
 * (but not MersenneTwister) stated that nextDouble selects uniformly from
 * the full-open interval [0,1].  It does not.  nextDouble's contract is
 * identical across MersenneTwisterFast, MersenneTwister, and java.util.Random,
 * namely, selection in the half-open interval [0,1).  That is, 1.0 should
 * not be returned.  A similar contract exists in nextFloat.
 *
 * <p><b>Changes Since V6:</b> License has changed from LGPL to BSD.
 * New timing information to compare against
 * java.util.Random.  Recent versions of HotSpot have helped Random increase
 * in speed to the point where it is faster than MersenneTwister but slower
 * than MersenneTwisterFast (which should be the case, as it's a less complex
 * algorithm but is synchronized).
 *
 * <p><b>Changes Since V5:</b> New empty constructor made to work the same
 * as java.util.Random -- namely, it seeds based on the current time in
 * milliseconds.
 *
 * <p><b>Changes Since V4:</b> New initialization algorithms.  See
 * (see <a href="http://www.math.keio.ac.jp/matumoto/MT2002/emt19937ar.html"</a>
 * http://www.math.keio.ac.jp/matumoto/MT2002/emt19937ar.html</a>)
 *
 * <p>The MersenneTwister code is based on standard MT19937 C/C++
 * code by Takuji Nishimura,
 * with suggestions from Topher Cooper and Marc Rieffel, July 1997.
 * The code was originally translated into Java by Michael Lecuyer,
 * January 1999, and the original code is Copyright (c) 1999 by Michael Lecuyer.
 *
 * <h3>Java notes</h3>
 *
 * <p>This implementation implements the bug fixes made
 * in Java 1.2's version of Random, which means it can be used with
 * earlier versions of Java.  See
 * <a href="http://www.javasoft.com/products/jdk/1.2/docs/api/java/util/Random.html">
 * the JDK 1.2 java.util.Random documentation</a> for further documentation
 * on the random-number generation contracts made.  Additionally, there's
 * an undocumented bug in the JDK java.util.Random.nextBytes() method,
 * which this code fixes.
 *
 * <p> Just like java.util.Random, this
 * generator accepts a long seed but doesn't use all of it.  java.util.Random
 * uses 48 bits.  The Mersenne Twister instead uses 32 bits (int size).
 * So it's best if your seed does not exceed the int range.
 *
 * <p>MersenneTwister can be used reliably
 * on JDK version 1.1.5 or above.  Earlier Java versions have serious bugs in
 * java.util.Random; only MersenneTwisterFast (and not MersenneTwister nor
 * java.util.Random) should be used with them.
 *
 * <h3>License</h3>
 *
 * Copyright (c) 2003 by Sean Luke. <br>
 * Portions copyright (c) 1993 by Michael Lecuyer. <br>
 * All rights reserved. <br>
 *
 * <p>Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * <ul>
 * <li> Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * <li> Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * <li> Neither the name of the copyright owners, their employers, nor the
 * names of its contributors may be used to endorse or promote products
 * derived from this software without specific prior written permission.
 * </ul>
 * <p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 @version 13
*/

// Note: this class is hard-inlined in all of its methods.  This makes some of
// the methods well-nigh unreadable in their complexity.  In fact, the Mersenne
// Twister is fairly easy code to understand: if you're trying to get a handle
// on the code, I strongly suggest looking at MersenneTwister.java first.
// -- Sean

public class MersenneTwisterFast implements Serializable, Cloneable
    {
    // Period parameters
    private static final int N = 624;
    private static final int M = 397;
    private static final int MATRIX_A = 0x9908b0df;   //    private static final * constant vector a
    private static final int UPPER_MASK = 0x80000000; // most significant w-r bits
    private static final int LOWER_MASK = 0x7fffffff; // least significant r bits


    // Tempering parameters
    private static final int TEMPERING_MASK_B = 0x9d2c5680;
    private static final int TEMPERING_MASK_C = 0xefc60000;

    private int mt[]; // the array for the state vector
    private int mti; // mti==N+1 means mt[N] is not initialized
    private int mag01[];

    // a good initial seed (of int size, though stored in a long)
    //private static final long GOOD_SEED = 4357;

    private double __nextNextGaussian;
    private boolean __haveNextNextGaussian;

    /* We're overriding all internal data, to my knowledge, so this should be okay */
    public Object clone() throws CloneNotSupportedException
        {
        MersenneTwisterFast f = (MersenneTwisterFast)(super.clone());
        f.mt = (int[])(mt.clone());
        f.mag01 = (int[])(mag01.clone());
        return f;
        }

    public boolean stateEquals(Object o)
        {
        if (o==this) return true;
        if (o == null || !(o instanceof MersenneTwisterFast))
            return false;
        MersenneTwisterFast other = (MersenneTwisterFast) o;
        if (mti != other.mti) return false;
        for(int x=0;x<mag01.length;x++)
            if (mag01[x] != other.mag01[x]) return false;
        for(int x=0;x<mt.length;x++)
            if (mt[x] != other.mt[x]) return false;
        return true;
        }

    /** Reads the entire state of the MersenneTwister RNG from the stream */
    public void readState(DataInputStream stream) throws IOException
        {
        int len = mt.length;
        for(int x=0;x<len;x++) mt[x] = stream.readInt();

        len = mag01.length;
        for(int x=0;x<len;x++) mag01[x] = stream.readInt();

        mti = stream.readInt();
        __nextNextGaussian = stream.readDouble();
        __haveNextNextGaussian = stream.readBoolean();
        }

    /** Writes the entire state of the MersenneTwister RNG to the stream */
    public void writeState(DataOutputStream stream) throws IOException
        {
        int len = mt.length;
        for(int x=0;x<len;x++) stream.writeInt(mt[x]);

        len = mag01.length;
        for(int x=0;x<len;x++) stream.writeInt(mag01[x]);

        stream.writeInt(mti);
        stream.writeDouble(__nextNextGaussian);
        stream.writeBoolean(__haveNextNextGaussian);
        }

    /**
     * Constructor using the default seed.
     */
    public MersenneTwisterFast()
        {
        this(System.currentTimeMillis());
        }

    /**
     * Constructor using a given seed.  Though you pass this seed in
     * as a long, it's best to make sure it's actually an integer.
     *
     */
    public MersenneTwisterFast(final long seed)
        {
        setSeed(seed);
        }


    /**
     * Constructor using an array of integers as seed.
     * Your array must have a non-zero length.  Only the first 624 integers
     * in the array are used; if the array is shorter than this then
     * integers are repeatedly used in a wrap-around fashion.
     */
    public MersenneTwisterFast(final int[] array)
        {
        setSeed(array);
        }


    /**
     * Initalize the pseudo random number generator.  Don't
     * pass in a long that's bigger than an int (Mersenne Twister
     * only uses the first 32 bits for its seed).
     */

    synchronized public void setSeed(final long seed)
        {
        // Due to a bug in java.util.Random clear up to 1.2, we're
        // doing our own Gaussian variable.
        __haveNextNextGaussian = false;

        mt = new int[N];

        mag01 = new int[2];
        mag01[0] = 0x0;
        mag01[1] = MATRIX_A;

        mt[0]= (int)(seed & 0xffffffff);
        for (mti=1; mti<N; mti++)
            {
            mt[mti] =
                (1812433253 * (mt[mti-1] ^ (mt[mti-1] >>> 30)) + mti);
            /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
            /* In the previous versions, MSBs of the seed affect   */
            /* only MSBs of the array mt[].                        */
            /* 2002/01/09 modified by Makoto Matsumoto             */
            mt[mti] &= 0xffffffff;
            /* for >32 bit machines */
            }
        }


    /**
     * Sets the seed of the MersenneTwister using an array of integers.
     * Your array must have a non-zero length.  Only the first 624 integers
     * in the array are used; if the array is shorter than this then
     * integers are repeatedly used in a wrap-around fashion.
     */

    synchronized public void setSeed(final int[] array)
        {
        if (array.length == 0)
            throw new IllegalArgumentException("Array length must be greater than zero");
        int i, j, k;
        setSeed(19650218);
        i=1; j=0;
        k = (N>array.length ? N : array.length);
        for (; k!=0; k--)
            {
            mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >>> 30)) * 1664525)) + array[j] + j; /* non linear */
            mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
            i++;
            j++;
            if (i>=N) { mt[0] = mt[N-1]; i=1; }
            if (j>=array.length) j=0;
            }
        for (k=N-1; k!=0; k--)
            {
            mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >>> 30)) * 1566083941)) - i; /* non linear */
            mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
            i++;
            if (i>=N)
                {
                mt[0] = mt[N-1]; i=1;
                }
            }
        mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
        }


    public final int nextInt()
        {
        int y;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return y;
        }



    public final short nextShort()
        {
        int y;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return (short)(y >>> 16);
        }



    public final char nextChar()
        {
        int y;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return (char)(y >>> 16);
        }


    public final boolean nextBoolean()
        {
        int y;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return (boolean)((y >>> 31) != 0);
        }



    /** This generates a coin flip with a probability <tt>probability</tt>
        of returning true, else returning false.  <tt>probability</tt> must
        be between 0.0 and 1.0, inclusive.   Not as precise a random real
        event as nextBoolean(double), but twice as fast. To explicitly
        use this, remember you may need to cast to float first. */

    public final boolean nextBoolean(final float probability)
        {
        int y;

        if (probability < 0.0f || probability > 1.0f)
            throw new IllegalArgumentException ("probability must be between 0.0 and 1.0 inclusive.");
        if (probability==0.0f) return false;            // fix half-open issues
        else if (probability==1.0f) return true;        // fix half-open issues
        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return (y >>> 8) / ((float)(1 << 24)) < probability;
        }


    /** This generates a coin flip with a probability <tt>probability</tt>
        of returning true, else returning false.  <tt>probability</tt> must
        be between 0.0 and 1.0, inclusive. */

    public final boolean nextBoolean(final double probability)
        {
        int y;
        int z;

        if (probability < 0.0 || probability > 1.0)
            throw new IllegalArgumentException ("probability must be between 0.0 and 1.0 inclusive.");
        if (probability==0.0) return false;             // fix half-open issues
        else if (probability==1.0) return true; // fix half-open issues
        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];
                }
            z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];

            mti = 0;
            }

        z = mt[mti++];
        z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)
        z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)
        z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)
        z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)

        /* derived from nextDouble documentation in jdk 1.2 docs, see top */
        return ((((long)(y >>> 6)) << 27) + (z >>> 5)) / (double)(1L << 53) < probability;
        }


    public final byte nextByte()
        {
        int y;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return (byte)(y >>> 24);
        }


    public final void nextBytes(byte[] bytes)
        {
        int y;

        for (int x=0;x<bytes.length;x++)
            {
            if (mti >= N)   // generate N words at one time
                {
                int kk;
                final int[] mt = this.mt; // locals are slightly faster
                final int[] mag01 = this.mag01; // locals are slightly faster

                for (kk = 0; kk < N - M; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                for (; kk < N-1; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

                mti = 0;
                }

            y = mt[mti++];
            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

            bytes[x] = (byte)(y >>> 24);
            }
        }


    public final long nextLong()
        {
        int y;
        int z;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];
                }
            z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];

            mti = 0;
            }

        z = mt[mti++];
        z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)
        z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)
        z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)
        z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)

        return (((long)y) << 32) + (long)z;
        }



    /** Returns a long drawn uniformly from 0 to n-1.  Suffice it to say,
        n must be > 0, or an IllegalArgumentException is raised. */
    public final long nextLong(final long n)
        {
        if (n<=0)
            throw new IllegalArgumentException("n must be > 0");

        long bits, val;
        do
            {
            int y;
            int z;

            if (mti >= N)   // generate N words at one time
                {
                int kk;
                final int[] mt = this.mt; // locals are slightly faster
                final int[] mag01 = this.mag01; // locals are slightly faster

                for (kk = 0; kk < N - M; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                for (; kk < N-1; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

                mti = 0;
                }

            y = mt[mti++];
            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

            if (mti >= N)   // generate N words at one time
                {
                int kk;
                final int[] mt = this.mt; // locals are slightly faster
                final int[] mag01 = this.mag01; // locals are slightly faster

                for (kk = 0; kk < N - M; kk++)
                    {
                    z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];
                    }
                for (; kk < N-1; kk++)
                    {
                    z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];
                    }
                z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];

                mti = 0;
                }

            z = mt[mti++];
            z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)
            z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)
            z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)
            z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)

            bits = (((((long)y) << 32) + (long)z) >>> 1);
            val = bits % n;
            } while (bits - val + (n-1) < 0);
        return val;
        }

    /** Returns a random double in the half-open range from [0.0,1.0).  Thus 0.0 is a valid
        result but 1.0 is not. */
    public final double nextDouble()
        {
        int y;
        int z;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];
                }
            z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];

            mti = 0;
            }

        z = mt[mti++];
        z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)
        z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)
        z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)
        z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)

        /* derived from nextDouble documentation in jdk 1.2 docs, see top */
        return ((((long)(y >>> 6)) << 27) + (z >>> 5)) / (double)(1L << 53);
        }





    public final double nextGaussian()
        {
        if (__haveNextNextGaussian)
            {
            __haveNextNextGaussian = false;
            return __nextNextGaussian;
            }
        else
            {
            double v1, v2, s;
            do
                {
                int y;
                int z;
                int a;
                int b;

                if (mti >= N)   // generate N words at one time
                    {
                    int kk;
                    final int[] mt = this.mt; // locals are slightly faster
                    final int[] mag01 = this.mag01; // locals are slightly faster

                    for (kk = 0; kk < N - M; kk++)
                        {
                        y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                        }
                    for (; kk < N-1; kk++)
                        {
                        y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                        }
                    y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                    mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

                    mti = 0;
                    }

                y = mt[mti++];
                y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
                y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
                y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
                y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

                if (mti >= N)   // generate N words at one time
                    {
                    int kk;
                    final int[] mt = this.mt; // locals are slightly faster
                    final int[] mag01 = this.mag01; // locals are slightly faster

                    for (kk = 0; kk < N - M; kk++)
                        {
                        z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+M] ^ (z >>> 1) ^ mag01[z & 0x1];
                        }
                    for (; kk < N-1; kk++)
                        {
                        z = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+(M-N)] ^ (z >>> 1) ^ mag01[z & 0x1];
                        }
                    z = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                    mt[N-1] = mt[M-1] ^ (z >>> 1) ^ mag01[z & 0x1];

                    mti = 0;
                    }

                z = mt[mti++];
                z ^= z >>> 11;                          // TEMPERING_SHIFT_U(z)
                z ^= (z << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(z)
                z ^= (z << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(z)
                z ^= (z >>> 18);                        // TEMPERING_SHIFT_L(z)

                if (mti >= N)   // generate N words at one time
                    {
                    int kk;
                    final int[] mt = this.mt; // locals are slightly faster
                    final int[] mag01 = this.mag01; // locals are slightly faster

                    for (kk = 0; kk < N - M; kk++)
                        {
                        a = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+M] ^ (a >>> 1) ^ mag01[a & 0x1];
                        }
                    for (; kk < N-1; kk++)
                        {
                        a = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+(M-N)] ^ (a >>> 1) ^ mag01[a & 0x1];
                        }
                    a = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                    mt[N-1] = mt[M-1] ^ (a >>> 1) ^ mag01[a & 0x1];

                    mti = 0;
                    }

                a = mt[mti++];
                a ^= a >>> 11;                          // TEMPERING_SHIFT_U(a)
                a ^= (a << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(a)
                a ^= (a << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(a)
                a ^= (a >>> 18);                        // TEMPERING_SHIFT_L(a)

                if (mti >= N)   // generate N words at one time
                    {
                    int kk;
                    final int[] mt = this.mt; // locals are slightly faster
                    final int[] mag01 = this.mag01; // locals are slightly faster

                    for (kk = 0; kk < N - M; kk++)
                        {
                        b = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+M] ^ (b >>> 1) ^ mag01[b & 0x1];
                        }
                    for (; kk < N-1; kk++)
                        {
                        b = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                        mt[kk] = mt[kk+(M-N)] ^ (b >>> 1) ^ mag01[b & 0x1];
                        }
                    b = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                    mt[N-1] = mt[M-1] ^ (b >>> 1) ^ mag01[b & 0x1];

                    mti = 0;
                    }

                b = mt[mti++];
                b ^= b >>> 11;                          // TEMPERING_SHIFT_U(b)
                b ^= (b << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(b)
                b ^= (b << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(b)
                b ^= (b >>> 18);                        // TEMPERING_SHIFT_L(b)

                /* derived from nextDouble documentation in jdk 1.2 docs, see top */
                v1 = 2 *
                    (((((long)(y >>> 6)) << 27) + (z >>> 5)) / (double)(1L << 53))
                    - 1;
                v2 = 2 * (((((long)(a >>> 6)) << 27) + (b >>> 5)) / (double)(1L << 53))
                    - 1;
                s = v1 * v1 + v2 * v2;
                } while (s >= 1 || s==0);
            double multiplier = /*Strict*/Math.sqrt(-2 * /*Strict*/Math.log(s)/s);
            __nextNextGaussian = v2 * multiplier;
            __haveNextNextGaussian = true;
            return v1 * multiplier;
            }
        }





    /** Returns a random float in the half-open range from [0.0f,1.0f).  Thus 0.0f is a valid
        result but 1.0f is not. */
    public final float nextFloat()
        {
        int y;

        if (mti >= N)   // generate N words at one time
            {
            int kk;
            final int[] mt = this.mt; // locals are slightly faster
            final int[] mag01 = this.mag01; // locals are slightly faster

            for (kk = 0; kk < N - M; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            for (; kk < N-1; kk++)
                {
                y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                }
            y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
            mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

            mti = 0;
            }

        y = mt[mti++];
        y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
        y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
        y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
        y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

        return (y >>> 8) / ((float)(1 << 24));
        }



    /** Returns an integer drawn uniformly from 0 to n-1.  Suffice it to say,
        n must be > 0, or an IllegalArgumentException is raised. */
    public final int nextInt(final int n)
        {
        if (n<=0)
            throw new IllegalArgumentException("n must be > 0");

        if ((n & -n) == n)  // i.e., n is a power of 2
            {
            int y;

            if (mti >= N)   // generate N words at one time
                {
                int kk;
                final int[] mt = this.mt; // locals are slightly faster
                final int[] mag01 = this.mag01; // locals are slightly faster

                for (kk = 0; kk < N - M; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                for (; kk < N-1; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

                mti = 0;
                }

            y = mt[mti++];
            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

            return (int)((n * (long) (y >>> 1) ) >> 31);
            }

        int bits, val;
        do
            {
            int y;

            if (mti >= N)   // generate N words at one time
                {
                int kk;
                final int[] mt = this.mt; // locals are slightly faster
                final int[] mag01 = this.mag01; // locals are slightly faster

                for (kk = 0; kk < N - M; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+M] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                for (; kk < N-1; kk++)
                    {
                    y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
                    mt[kk] = mt[kk+(M-N)] ^ (y >>> 1) ^ mag01[y & 0x1];
                    }
                y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                mt[N-1] = mt[M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

                mti = 0;
                }

            y = mt[mti++];
            y ^= y >>> 11;                          // TEMPERING_SHIFT_U(y)
            y ^= (y << 7) & TEMPERING_MASK_B;       // TEMPERING_SHIFT_S(y)
            y ^= (y << 15) & TEMPERING_MASK_C;      // TEMPERING_SHIFT_T(y)
            y ^= (y >>> 18);                        // TEMPERING_SHIFT_L(y)

            bits = (y >>> 1);
            val = bits % n;
            } while(bits - val + (n-1) < 0);
        return val;
        }
    }



================================================
FILE: src/main/resources/scalala.scala
================================================
import scalala.scalar._;
import scalala.tensor.::;
import scalala.tensor.mutable._;
import scalala.tensor.dense._;
import scalala.tensor.sparse._;
import scalala.library.Library._;
import scalala.library.LinearAlgebra._;
import scalala.library.Statistics._;
import scalala.library.Plotting._;
import scalala.operators.Implicits._;



================================================
FILE: src/main/scala/scalala/ScalalaConsole.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 * 
 * Copyright (C) 2008- Daniel Ramage
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA 
 */
package scalala;

/**
 * Runs Scalala in a console.
 * 
 * @author dlwh,dramage
 */
object ScalalaConsole {
  def main(args : Array[String]) {
    // read scalala.scala to a tmp file
    val stream = this.getClass.getClassLoader.getResourceAsStream("scalala.scala");
    val file = java.io.File.createTempFile("scalala-startup-", ".scala");
    file.deleteOnExit;
    val fos = new java.io.PrintStream(new java.io.FileOutputStream(file));
    for (line <- scala.io.Source.fromInputStream(stream).getLines()) {
      fos.println(line);
    }
    fos.close();

    // redirect to invoking the standard scala main method
    val method = Class.forName("scala.tools.nsc.MainGenericRunner").
      getMethod("main", classOf[Array[String]]);

    // augmented arguments
    val aurg : Object = (
      List[String](
        "-nocompdaemon",
        "-classpath", System.getProperty("java.class.path"),
        "-no-specialization",
        "-Yrepl-sync",
        "-usejavacp",
        "-i", file.getAbsolutePath
      ) ++ args
    ).toArray[String];

    method.invoke(null, aurg);
  }
  
  /** The width of the console, or 80 if it can't be discovered. */
  lazy val terminalWidth : Int = {
    // this ugly try-catch is here to use scala's built-in jline,
    // which only exists in scala > 2.9
    try {
      type Terminal = { def getWidth() : Int; def getHeight() : Int; }
      val terminal = Class.forName("scala.tools.jline.TerminalFactory").
        getMethod("create").invoke(null).asInstanceOf[Terminal];
      terminal.getWidth()
    } catch {
      case _ => try {
        type Terminal = { def getTerminalWidth() : Int; def getTerminalHeight() : Int; }
        val terminal = Class.forName("jline.Terminal").
          getMethod("getInstance").invoke(null).asInstanceOf[Terminal];
        terminal.getTerminalWidth()
      } catch {
        case _ => 80
      }
    }
  };

  /** The height of the console, or 24 if it can't be discovered. */
  lazy val terminalHeight : Int = {
    // this ugly try-catch is here to use scala's built-in jline,
    // which only exists in scala > 2.9
    try {
      type Terminal = { def getWidth() : Int; def getHeight() : Int; }
      val terminal = Class.forName("scala.tools.jline.TerminalFactory").
        getMethod("create").invoke(null).asInstanceOf[Terminal];
      terminal.getHeight();
    } catch {
      case _ => try {
        type Terminal = { def getTerminalWidth() : Int; def getTerminalHeight() : Int; }
        val terminal = Class.forName("jline.Terminal").
          getMethod("getInstance").invoke(null).asInstanceOf[Terminal];
        terminal.getTerminalHeight()
      } catch {
        case _ => 24
      }
    }
  };
}



================================================
FILE: src/main/scala/scalala/collection/sparse/SparseArray.scala
================================================
/*
 Copyright 2009 David Hall, Daniel Ramage
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at 
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License. 
*/

package scalala.collection.sparse;

import scala.collection.generic._;
import scala.collection.mutable._;

import scalala.operators._;
import scalala.scalar.Scalar
import java.util.Arrays
;

/**
 * <p>Nearly-drop-in replacement for Array[T](length) that does not store
 * default array values.  Internally, the SparseArray data structure
 * stores an array of indexes in packed, sorted order, and a
 * corresponding packed array of values.  Updates are linear in
 * the number of non-zero array elements, while accesses are
 * logarithmic.  This class is not threadsafe for simultaneous
 * reads and writes, but more than one thread can read simultaneously
 * if no threads are writing.</p>
 *
 * <p>Note that the DefaultArrayValue must be a constant reference -- no
 * clever tricks like creating new instances of type T are supported
 * by the nature of the way this map works.  Otherwise, iterating
 * over the size of the array would cause the SparseArray to become
 * (inefficiently) dense.</p>
 *
 * @param length The virtual length of the array.
 * @param index The indices of the array, in packed sorted order.
 * @param data The data of the array, in corresponding positions to index.
 * @param used The number of used elements in index and data.
 * @param initialActiveLength The initial length of the sparse data structures
 *   when creating new instances.
 *
 * @author dlwh, dramage
 */
@SerialVersionUID(1L)
final class SparseArray[@specialized T]
(val length : Int, protected var index : Array[Int], protected var data : Array[T], protected var used : Int, initialActiveLength : Int)
(implicit m : ClassManifest[T], df : DefaultArrayValue[T]) extends Serializable {

  def copy: SparseArray[T] = {
    val newData = m.newArray(data.length)
    Array.copy(data,0,newData,0,data.length)
    new SparseArray(length, Arrays.copyOf(index, index.length), newData, used, initialActiveLength)
  }


  def this(length : Int, initialActiveLength : Int = 3)(implicit m : ClassManifest[T], d : DefaultArrayValue[T]) =
    this(length, new Array[Int](initialActiveLength), new Array[T](initialActiveLength), 0, initialActiveLength)(m, d);

  checkInvariants()
  
  private def checkInvariants() { // check rep invariants
    require(length >= 0, "Length must be non-negative");
    require(used >= 0 && used <= length, "Used must be <= length and >= 0");
    if (used > 0) {
      require(index(0) >= 0, "Indexes must be ordered and non-negative");
      var i = 1;
      while (i < used) {
        require(index(i-1) < index(i) && index(i) >= 0, "Indexes must be ordered and non-negative");
        i +=1;
      }
    }
  }

  /** Default value. */
  val default = df.value;

  /** Iterator over used indexes and values */
  def iterator = Iterator.range(0, used).map(i => (index(i),data(i)));

  /** Used indexes. */
  def indexIterator = index.iterator.take(used);

  /** Used values. */
  def valueIterator = data.iterator.take(used);

  /** Key value pairs of non-default entries. */
  def activeIterator = indexIterator zip valueIterator;

  /** A copy of the keys in this array. */
  def indexArray : Array[Int] = index.take(used);

  /** A copy of the values in this array. */
  def valueArray : Array[T] = data.take(used);

  /** Raw access to the underlying data array. Use with caution */
  def rawValueArray : Array[T] = data

  /**
   * Returns the offset into index and data for the requested vector
   * index.  If the requested index is not found, the return value is
   * negative and can be converted into an insertion point with ~rv.
   */
  private def findOffset(i : Int) : Int = {
    if (i < 0 || i >= length)
      throw new IndexOutOfBoundsException("Index "+i+" out of bounds [0,"+used+")");

    if (used == 0) {
      // empty list; do nothing
      return -1;
    } else if (i > index(used-1)) {
      // special case for end of list - this is a big win for growing sparse arrays
      return ~used;
    } else {
      // regular binary search from begin to end (inclusive)
      var begin = 0;
      var end = used - 1;

      // Simple optimization: position i can't be after offset i.
      if(end > i)
        end = i;

      var mid = (end + begin) >> 1;
      while (begin <= end) {
        mid = (end + begin) >> 1;
        if (index(mid) < i)
          begin = mid + 1;
        else if (index(mid) > i)
          end = mid - 1;
        else
          return mid;
      }

      // no match found, return insertion point
      if (i <= index(mid))
        return ~mid;       // Insert here (before mid)
      else
        return ~(mid + 1); // Insert after mid
    }
  }

  def apply(i : Int) : T = {
    val offset = findOffset(i);
    if (offset >= 0) data(offset) else default;
  }

  def get(i: Int) : Option[T] = {
    val offset = findOffset(i);
    if (offset >= 0) Some(data(offset)) else None;
  }

  def getOrElse(i : Int, value : =>T) : T = {
    val offset = findOffset(i);
    if (offset >= 0) data(offset) else value;
  }

  def getOrElseUpdate(i : Int, value : =>T) : T = {
    val offset = findOffset(i);
    if (offset >= 0) data(offset)
    else {
      val v = value;
      update(i,v)
      v;
    }
  }

  /** Returns the size of the array. */
  def activeLength = used;

  /** Returns the index of the item stored at the given offset. */
  def indexAt(offset : Int) : Int = {
    if (offset >= used) throw new ArrayIndexOutOfBoundsException();
    index(offset);
  }

  /** Returns the value of the item stored at the given offset. */
  def valueAt(offset : Int) : T = {
    if (offset >= used) throw new ArrayIndexOutOfBoundsException();
    data(offset);
  }

  /**
   * Sets the given value at the given index if the value is not
   * equal to the current default.  The data and
   * index arrays will be grown to support the insertion if
   * necessary.  The growth schedule doubles the amount
   * of allocated memory at each allocation request up until
   * the sparse array contains 1024 values, at which point
   * the growth is additive: an additional n * 1024 spaces will
   * be allocated for n in 1,2,4,8,16.  The largest amount of
   * space added to this vector will be an additional 16*1024*(sizeof(T)+4),
   * which is 196608 bytes at a time for a SparseVector[Double],
   * although more space is needed temporarily while moving to the
   * new arrays.
   */
  def update(i : Int, value : T) = {
    val offset = findOffset(i);
    if (offset >= 0) {
      // found at offset
      data(offset) = value;
    } else if (value != default) {
      // need to insert at ~offset
      val insertPos = ~offset;

      used += 1;

      if (used > data.length) {
        // need to grow array
        val newLength = {
          if      (data.length == 0)     { 4 }
          else if (data.length < 0x0400) { data.length * 2 }
          else if (data.length < 0x0800) { data.length + 0x0400 }
          else if (data.length < 0x1000) { data.length + 0x0800 }
          else if (data.length < 0x2000) { data.length + 0x1000 }
          else if (data.length < 0x4000) { data.length + 0x2000 }
          else { data.length + 0x4000 };
        };

        // allocate new arrays
        val newIndex = new Array[Int](newLength);
        val newData  = new Array[T](newLength);

        // copy existing data into new arrays
        System.arraycopy(index, 0, newIndex, 0, insertPos);
        System.arraycopy(data, 0, newData, 0, insertPos);
        System.arraycopy(index, insertPos, newIndex, insertPos + 1, used - insertPos - 1);
        System.arraycopy(data,  insertPos, newData,  insertPos + 1, used - insertPos - 1);
        
        // update pointers
        index = newIndex;
        data = newData;
      } else if (used - insertPos > 1) {
        // need to make room for new element mid-array
        System.arraycopy(index, insertPos, index, insertPos + 1, used - insertPos - 1);
        System.arraycopy(data,  insertPos, data,  insertPos + 1, used - insertPos - 1);
      }

      // assign new value
      index(insertPos) = i;
      data(insertPos) = value;
    }
  }

  /** Clears this array, resetting to the initial size. */
  def clear() {
    use(new Array[Int](initialActiveLength), new Array[T](initialActiveLength), 0);
  }

  /** Pre-allocate space in this array for all active indexes in other. */
  def reserve[O](other : SparseArray[O]) {
    val rv = new SparseArray[T](this.length, this.used + other.used);
    var i = 0;
    var j = 0;
    while (j < other.used) {
      val indexI = index(i);
      val indexJ = index(j);
      while (i < used && indexI < indexJ) {
        rv(indexI) = data(i);
        i += 1;
      }
      rv(indexJ) = this(indexJ);
      j += 1;
    }
    while (i < used) {
      rv(index(i)) = data(i);
      i += 1;
    }
    use(rv.index, rv.data, rv.used);
  }

  /** Compacts the array by removing all stored default values. */
  def compact() {
    val nz = { // number of non-zeros
      var _nz = 0;
      var i = 0;
      while (i < used) {
        if (data(i) != default) {
          _nz += 1;
        }
        i += 1;
      }
      _nz;
    }

    val newData  = new Array[T](nz);
    val newIndex = new Array[Int](nz);

    var i = 0;
    var o = 0;
    while (i < used) {
      if (data(i) != default) {
        newData(o) = data(i);
        newIndex(o) = index(i);
        o += 1;
      }
      i += 1;
    }

    use(newIndex, newData, nz);
  }

  /** Use the given index and data arrays, of which the first inUsed are valid. */
  private def use(inIndex : Array[Int], inData : Array[T], inUsed : Int) = {
    // no need to rep-check since method is private and all callers satisfy
    // these invariants.

    data = inData;
    index = inIndex;
    used = inUsed;
  }
  
  /** Sets this array to be a copy of the given other array. */
  def set(that : SparseArray[T]) = {
    if (this.length != that.length) {
      throw new IllegalArgumentException("SparseArrays must be the same length");
    }
    use(that.index.clone, that.data.clone, that.used);
  }

  private def checkrep() {
    if (index == null || data == null)
      throw new IllegalArgumentException("Index and data must be non-null");
    if (index.length != data.length)
      throw new IllegalArgumentException("Index and data sizes do not match");
    if (index.length < used)
      throw new IllegalArgumentException("Used is greater than provided array");
    if (index(0) < 0 || index(0) >= used)
      throw new IllegalArgumentException("use inIndex out of range contains illegal offset @ 0");
    var i = 1;
    while (i < used) {
      if (index(i) < 0 || index(i) >= used || index(i) < index(i-1))
        throw new IllegalArgumentException("use inIndex out of range contains illegal offset @ "+i);
      i += 1;
    }
  }

  /**
   * Maps all values.  If f(this.default) is not equal to the new default
   * value, the result may be an efficiently dense (or almost dense) paired
   * array.
   */
  def map[B:ClassManifest:DefaultArrayValue](f : T=>B) : SparseArray[B] = {
    val newDefault = implicitly[DefaultArrayValue[B]].value;
    if (used < length && f(default) == newDefault) {
      // some default values but f(default) is still default
      val newIndex = new Array[Int](used);
      val newData = new Array[B](used);
      var i = 0; var o = 0;
      while (i < used) {
        newIndex(o) = index(i);
        val newValue = f(data(i));
        if (newValue != newDefault) {
          newData(o) = newValue;
          o += 1;
        }
        i += 1;
      }
      new SparseArray[B](length, newIndex, newData, o, initialActiveLength);
    } else {
      // no default values stored or f(default) is non-default
      val newDefault = f(default);
      val newIndex = new Array[Int](length);
      val newData = new Array[B](length);
      var i = 0;
      var o = 0;
      while (i < used) {
        while (o < index(i)) {
          newIndex(o) = o;
          newData(o) = newDefault;
          o += 1;
        }
        newIndex(o) = o;
        newData(o) = f(data(i));
        o += 1;
        i += 1;
      }
      while (o < length) {
        newIndex(o) = o;
        newData(o) = newDefault;
        o += 1;
      }
      val rv = new SparseArray[B](length, newIndex, newData, length, initialActiveLength);
      rv.compact;
      rv;
    }
  }

  /**
   * Filter's the array by removing all values for which f is false.
   */
  def filter(f : T=>Boolean) : SparseArray[T] = {
    val newIndex = new Array[Int](used);
    val newData = new Array[T](used);
    var i = 0; var o = 0;
    while (i < used) {
      if (f(data(i))) {
        newIndex(o) = index(i) - (i - o);
        newData(o) = data(i);
        o += 1;
      }
      i += 1;
    }

    if (f(default)) {
      // if default values are accepted, assume we're full length.
      var newLength = length - (i - o);
      
      // ... and subtract from that length how many defined tail elements
      // were filtered ...
      var ii = used - 1;
      while (ii >= 0 && index(ii) > newIndex(o) && index(ii) == newLength - 1) {
        ii -= 1;
        newLength -= 1;
      }
      new SparseArray[T](newLength, newIndex, newData, o, initialActiveLength);
    } else {
      // if default values are not accepted, return a "dense" array by
      // setting each position in newIndex consecutively to forget missing
      // values
      val newLength = o;
      new SparseArray[T](newLength, Array.range(0,newLength), newData.take(newLength), newLength, initialActiveLength);
    }
  }

  /**
   * Tranforms all elements this array by applying the given function. If
   * f(default) == default, then only updates non-default values.  Otherwise,
   * the map essentially becomes dense -- not so efficient an operation!
   */
  def transform(f : T=>T) = {
    val newDefault = f(default);
    if (newDefault == default) {
      var i = 0;
      while (i < used) {
        data(i) = f(data(i));
        i += 1;
      }
    } else {
      val newIndex = Array.range(0, length);
      val newData = new Array[T](length);
      var i = 0;
      var o = 0;
      while (i < used) {
        while (o < index(i)) {
          newData(o) = newDefault;
          o += 1;
        }
        newData(o) = f(data(i));
        o += 1;
        i += 1;
      }
      while (o < length) {
        newData(o) = newDefault;
        o += 1;
      }
      use(newIndex, newData, length);
    }
  }

  /** Applies the given function to each non-default element. */
  def foreachActivePair[U](f: ((Int,T) => U)) {
    var i = 0;
    while(i < used) {
      f(index(i), data(i));
      i += 1;
    }
  }

  /** Applies the given function to each non-default element. */
  def foreachActiveValue[U](f: T => U) {
    var i = 0;
    while(i < used) {
      f(data(i));
      i += 1;
    }
  }

  /** Applies the given function to each non-default element. */
  def foreachActiveKey[U](f: Int => U) {
    var i = 0;
    while(i < used) {
      f(index(i));
      i += 1;
    }
  }

  def toArray =
    Array.tabulate(length)(apply);

  def toList =
    List.tabulate(length)(apply);

  def toIndexedSeq =
    List.tabulate(length)(apply);

  def toMap =
    (indexIterator zip valueIterator).toMap;

  override def hashCode = {
    var rv = 0;
    var i = 0;
    while (i < used) {
      if (data(i) != default) {
        rv += 17*rv + data(i).hashCode*7 + index(i);
      }
      i += 1;
    }
    rv;
  }

  override def equals(other : Any) : Boolean = other match {
    case that : SparseArray[_] =>
      var thisI = 0;
      var thatI = 0;
      while (thisI < this.used && thatI < that.used) {
        if (this.index(thisI) < that.index(thatI)) {
          if (this.data(thisI) != that.default) return false;
          thisI += 1;
        } else if (that.index(thatI) < this.index(thisI)) {
          if (that.data(thatI) != this.default) return false;
          thatI += 1;
        } else { // this.index(thisI) == that.index(thatI)
          if (this.data(thisI) != that.data(thatI)) return false;
          thisI += 1;
          thatI += 1;
        }
      }
      while (thisI < this.used) {
        if (this.data(thisI) != that.default) return false;
        thisI += 1;
      }
      while (thatI < that.used) {
        if (that.data(thatI) != this.default) return false;
        thatI += 1;
      }
      true;
    case _ => false;
  }
}

object SparseArray extends SparseArrayOps {
  def apply[@specialized T:ClassManifest:DefaultArrayValue](values : T*) = {
    val rv = new SparseArray[T](values.length);
    var i = 0;
    for (v <- values) {
      rv(i) = v;
      i += 1;
    }
    rv.compact;
    rv;
  }

  /**
   * Creates a SparseArray filled with the given value.  The value function
   * is called once initially to test if the returned value is equal to the
   * DefaultArrayValue - if so, an empty SparseArray with initialActiveLength
   * non-zero entries is returned.  Otherwise, an inefficient "dense"
   * SparseArray is returned.
   *
   * @author dramage
   */
  def fill[@specialized T:ClassManifest:DefaultArrayValue](length : Int, initialActiveLength : Int = 3)(value : =>T) : SparseArray[T] = {
    if (value != implicitly[DefaultArrayValue[T]].value) {
      val rv = new SparseArray[T](length = length, initialActiveLength = length);
      var i = 0;
      while (i < length) {
        rv(i) = value;
        i += 1;
      }
      rv;
    } else {
      new SparseArray[T](length = length, initialActiveLength = length);
    }
  }

  def create[@specialized T:ClassManifest:DefaultArrayValue](length : Int)(values : (Int,T)*) = {
    val rv = new SparseArray[T](length = length, initialActiveLength = values.length);
    for ((k,v) <- values) {
      rv(k) = v;
    }
    rv;
  }

  def tabulate[@specialized T:ClassManifest:DefaultArrayValue](length : Int, initialActiveLength : Int = 3)(fn : (Int => T)) = {
    val rv = new SparseArray[T](length = length, initialActiveLength = initialActiveLength);
    var i = 0;
    while (i < length) {
      val v = fn(i);
      if (v != rv.default) {
        rv(i) = v;
      }
      i += 1;
    }
    rv.compact;
    rv;
  }
  
  class RichSparseArray[V](override val repr : SparseArray[V])
  extends MutableNumericOps[SparseArray[V]];
  
  implicit def richSparseArray[V](repr : SparseArray[V]) =
    new RichSparseArray(repr);
  
}

trait LowerPrioritySparseArrayOps {
  /** Set sparse array with corresponding values from another array. */
  implicit def OpSetSparseArraySparseArrayCast[V1,V2]
  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])
  : BinaryUpdateOp[SparseArray[V1],SparseArray[V2],OpSet]
  = new BinaryUpdateOp[SparseArray[V1],SparseArray[V2],OpSet] {
    def opType = OpSet;
    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
      var i = 0;
      while (i < a.length) {
        a(i) = cast(b(i));
        i += 1;
      }
    }
  }
  
  /** Set sparse array with casted corresponding values from another array. */
  implicit def OpSetSparseArrayArrayCast[V1,V2]
  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])
  : BinaryUpdateOp[SparseArray[V1],Array[V2],OpSet]
  = new BinaryUpdateOp[SparseArray[V1],Array[V2],OpSet] {
    def opType = OpSet;
    def apply(a : SparseArray[V1], b : Array[V2]) = {
      var i = 0;
      while (i < a.length) {
        a(i) = cast(b(i));
        i += 1;
      }
    }
  }
  
  /** Set array to casted scalar. */
  implicit def OpSetSparseArrayScalarCast[V1,V2]
  (implicit cast : CanCast[V2,V1], s1 : Scalar[V1], s2 : Scalar[V2])
  : BinaryUpdateOp[SparseArray[V1],V2,OpSet]
  = new BinaryUpdateOp[SparseArray[V1],V2,OpSet] {
    def opType = OpSet;
    def apply(a : SparseArray[V1], b : V2) = { 
      val v = cast(b);
      var i = 0;
      while (i < a.length) {
        a(i) = v;
        i += 1;
      }
    }
  }
}

trait LowPrioritySparseArrayOps {
  /** Update sparse array with corresponding values from another sparse array. */
  implicit def OpUpdateSparseArraySparseArray[V1,V2,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,V1], c : CompatibleShape[V1,V2])
  : BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O]
  = new BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "Inputs must be the same length");
      var i = 0;
      while (i < a.length) {
        a(i) = op(a(i),b(i));
        i += 1;
      }
    }
  }
  
  /** Set array with corresponding values from another array. */
  implicit def OpSetSparseArraySparseArray[V](implicit s : Scalar[V])
  : BinaryUpdateOp[SparseArray[V],SparseArray[V],OpSet]
  = new BinaryUpdateOp[SparseArray[V],SparseArray[V],OpSet] {
    def opType = OpSet;
    def apply(a : SparseArray[V], b : SparseArray[V]) = { 
      require(a.length == b.length, "Inputs must be the same length");
      var i = 0;
      while (i < a.length) {
        a(i) = b(i);
        i += 1;
      }
    }
  }

  /** Update sparse array with corresponding values from another array. */
  implicit def OpUpdateSparseArrayArray[V1,V2,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,V1], c : CompatibleShape[V1,V2])
  : BinaryUpdateOp[SparseArray[V1], Array[V2], O]
  = new BinaryUpdateOp[SparseArray[V1], Array[V2], O] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : Array[V2]) = {
      require(a.length == b.length, "Inputs must be the same length");
      var i = 0;
      while (i < a.length) {
        a(i) = op(a(i),b(i));
        i += 1;
      }
    }
  }
  
  /** Set sparse array with corresponding values from another array. */
  implicit def OpSetSparseArrayArray[V](implicit s : Scalar[V])
  : BinaryUpdateOp[SparseArray[V],Array[V],OpSet]
  = new BinaryUpdateOp[SparseArray[V],Array[V],OpSet] {
    def opType = OpSet;
    def apply(a : SparseArray[V], b : Array[V]) = { 
      require(a.length == b.length, "Inputs must be the same length");
      var i = 0;
      while (i < a.length) {
        a(i) = b(i);
        i += 1;
      }
    }
  }
  
  /** Update sparse array with scalar. */
  implicit def OpUpdateSparseArrayScalar[V1,V2,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,V1], s : Scalar[V2])
  : BinaryUpdateOp[SparseArray[V1], V2, O]
  = new BinaryUpdateOp[SparseArray[V1], V2, O] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : V2) = {
      var i = 0;
      while (i < a.length) {
        a(i) = op(a(i),b);
        i += 1;
      }
    }
  }
  
  /** Set sparse array with scalar. */
  implicit def OpSetSparseArrayScalar[V](implicit s : Scalar[V], dv : DefaultArrayValue[V])
  : BinaryUpdateOp[SparseArray[V],V,OpSet]
  = new BinaryUpdateOp[SparseArray[V],V,OpSet] {
    def opType = OpSet;
    def apply(a : SparseArray[V], b : V) = {
      if (b == dv.value) {
        a.clear();
      } else {
        var i = 0;
        while (i < a.length) {
          a(i) = b;
          i += 1;
        }
      }
    }
  }
}

trait SparseArrayOps extends LowPrioritySparseArrayOps {

  //
  // UnaryOps
  //
  
  implicit def UnaryOp[V,RV,O<:OpType]
  (implicit op : UnaryOp[V,O,RV], dv : DefaultArrayValue[RV], mf : Manifest[RV])
  : UnaryOp[SparseArray[V],O,SparseArray[RV]]
  = new UnaryOp[SparseArray[V],O,SparseArray[RV]] {
    def opType = op.opType;
    def apply(a : SparseArray[V]) =
      a.map(op apply _);
  }
  
  //
  // BinaryOps
  //
  
  implicit def BinaryOpSparseArrayScalar[V1,V2,RV,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,RV], s : Scalar[V2], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])
  : BinaryOp[SparseArray[V1], V2, O, SparseArray[RV]]
  = new BinaryOp[SparseArray[V1], V2, O, SparseArray[RV]] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : V2) =
      a.map(v => op(v, b));
  }
  
  implicit def BinaryOpScalarSparseArray[V1,V2,RV,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,RV], s : Scalar[V1], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])
  : BinaryOp[V1, SparseArray[V2], O, SparseArray[RV]]
  = new BinaryOp[V1, SparseArray[V2], O, SparseArray[RV]] {
    def opType = op.opType;
    def apply(a : V1, b : SparseArray[V2]) =
      b.map(v => op(a, v));
  }

  implicit def BinaryOpSparseArraySparseArray[V1,V2,RV,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])
  : BinaryOp[SparseArray[V1],SparseArray[V2],O,SparseArray[RV]]
  = new BinaryOp[SparseArray[V1],SparseArray[V2],O,SparseArray[RV]] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
      // TODO: optimize
      if (try { op(a.default, b.default) == dv.value } catch { case _ => false; }) {
        outer(a, b);
      } else {
        all(a, b);
      }
    }

    /** Where both a and b have non-default values. */
    def inner(a : SparseArray[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](a.length);
      var aO = 0;
      var bO = 0;
      while (aO < a.activeLength && bO < b.activeLength) {
        val aI = a.indexAt(aO);
        val bI = b.indexAt(bO);
        if (aI < bI) {
          aO += 1;
        } else if (bI < aI) {
          bO += 1;
        } else {
          rv(aI) = op(a.valueAt(aO), b.valueAt(bO));
          aO += 1;
          bO += 1;
        }
      }
      rv;
    }
      
    /** Where either a or b has non-default values. */
    def outer(a : SparseArray[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](a.length, scala.math.max(a.activeLength,b.activeLength));
  
      var aO = 0;
      var bO = 0;
      while (aO < a.activeLength && bO < b.activeLength) {
        val aI = a.indexAt(aO);
        val bI = b.indexAt(bO);
        if (aI < bI) {
          rv(aI) = op(a.valueAt(aO), b.default);
          aO += 1;
        } else if (bI < aI) {
          rv(bI) = op(a.default, b.valueAt(bO));
          bO += 1;
        } else {
          rv(aI) = op(a.valueAt(aO), b.valueAt(bO));
          aO += 1;
          bO += 1;
        }
      }
  
      // process unpaired remaining from a
      while (aO < a.activeLength) {
        val aI = a.indexAt(aO);
        rv(aI) = op(a.valueAt(aO), b.default);
        aO += 1;
      }
  
      // process unpaired remaining from b
      while (bO < b.activeLength) {
        val bI = b.indexAt(bO);
        rv(bI) = op(a.default, b.valueAt(bO));
        bO += 1;
      }
  
      rv;
    }
    
    /** All values regardless of whether default or not. */
    def all(a : SparseArray[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](a.length, a.length);
  
      var i = 0;
      while (i < rv.length) {
        rv(i) = op(a(i),b(i));
        i += 1;
      }
      rv;
    }
  }

  implicit def BinaryOpSparseArrayArray[V1,V2,RV,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2],
   d2 : DefaultArrayValue[V2], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])
  : BinaryOp[SparseArray[V1],Array[V2],O,SparseArray[RV]]
  = new BinaryOp[SparseArray[V1],Array[V2],O,SparseArray[RV]] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : Array[V2]) = {
      // TODO: optimize
      allToSparse(a, b);
    }
    
    def inner(a : SparseArray[V1], b : Array[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](a.length, a.activeLength);
      var o = 0;
      while (o < a.activeLength) {
        val i = a.indexAt(o);
        rv(i) = op(a.valueAt(o), b(i));
        o += 1;
      }
      rv;
    }
    
    def allToDense(a : SparseArray[V1], b : Array[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new Array[RV](a.length);
      var i = 0;
      while (i < a.length) {
        rv(i) = op(a(i), b(i));
        i += 1;
      }
      rv;
    }
    
    def allToSparse(a : SparseArray[V1], b : Array[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](a.length, a.activeLength);
      var i = 0;
      while (i < a.length) {
        rv(i) = op(a(i), b(i));
        i += 1;
      }
      rv;
    }
  }

  implicit def BinaryOpArraySparseArray[V1,V2,RV,O<:OpType]
  (implicit op : BinaryOp[V1,V2,O,RV], c : CompatibleShape[V1,V2],
   d1 : DefaultArrayValue[V1], dv : DefaultArrayValue[RV], cm : ClassManifest[RV])
  : BinaryOp[Array[V1],SparseArray[V2],O,SparseArray[RV]]
  = new BinaryOp[Array[V1],SparseArray[V2],O,SparseArray[RV]] {
    def opType = op.opType;
    def apply(a : Array[V1], b : SparseArray[V2]) = {
      // TODO: optimize
      allToSparse(a, b);
    }
    
    def inner(a : Array[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](b.length, b.activeLength);
      var o = 0;
      while (o < b.activeLength) {
        val i = b.indexAt(o);
        rv(i) = op(a(i), b.valueAt(o));
        o += 1;
      }
      rv;
    }
    
    def allToDense(a : Array[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new Array[RV](b.length);
      var i = 0;
      while (i < a.length) {
        rv(i) = op(a(i), b(i));
        i += 1;
      }
      rv;
    }
    
    def allToSparse(a : Array[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "arrays have different lengths");
      val rv = new SparseArray[RV](b.length);
      var i = 0;
      while (i < a.length) {
        rv(i) = op(a(i), b(i));
        i += 1;
      }
      rv;
    }
  }

  /** Recurse on elements within an array. */
  implicit def BinaryUpdateOpRecurseSparseArraySparseArray[V1,V2,O<:OpType]
  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])
  : BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O]
  = new BinaryUpdateOp[SparseArray[V1], SparseArray[V2], O] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
      require(a.length == b.length, "Inputs must be the same length");
      var i = 0;
      while (i < a.length) {
        op(a(i),b(i));
        i += 1;
      }
    }
  }
  
  /** Recurse on elements within an array. */
  implicit def BinaryUpdateOpRecurseSparseArrayArray[V1,V2,O<:OpType]
  (implicit op : BinaryUpdateOp[V1,V2,O], c : CompatibleShape[V1,V2])
  : BinaryUpdateOp[SparseArray[V1], Array[V2], O]
  = new BinaryUpdateOp[SparseArray[V1], Array[V2], O] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : Array[V2]) = {
      require(a.length == b.length, "Inputs must be the same length");
      var i = 0;
      while (i < a.length) {
        op(a(i),b(i));
        i += 1;
      }
    }
  }
  
  /** Recurse on elements. */
  implicit def BinaryUpdateOpRecurseSparseArrayScalar[V1,V2,O<:OpType]
  (implicit op : BinaryUpdateOp[V1,V2,O], s : Scalar[V2])
  : BinaryUpdateOp[SparseArray[V1], V2, O]
  = new BinaryUpdateOp[SparseArray[V1], V2, O] {
    def opType = op.opType;
    def apply(a : SparseArray[V1], b : V2) = {
      var i = 0;
      while (i < a.length) {
        op(a(i),b);
        i += 1;
      }
    }
  }
  
///**
// * Base class for updating a SparseArray by another SparseArray.  Considers
// * only non-zeros in the left operand.  Base class of MulInto.
// *
// * @author dramage
// */
//class SparseArraySparseArrayUpdateLeftNZOp[V1,V2](implicit op : BinaryOp[V1,V2,V1])
//extends BinaryUpdateOp[SparseArray[V1],SparseArray[V2]] {
//  def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
//    if (a.length != b.length) {
//      throw new DomainException(this.getClass.getSimpleName + ": arrays have different lengths");
//    }
//    var aO = 0;
//    var bO = 0;
//    while (aO < a.activeLength && bO < b.activeLength) {
//      val aI = a.indexAt(aO);
//      val bI = b.indexAt(bO);
//      if (aI < bI) {
//        a(aI) = op(a.valueAt(aO), b.default);
//        aO += 1;
//      } else if (bI < aI) {
//        bO += 1;
//      } else {
//        a(aI) = op(a.valueAt(aO), b.valueAt(bO));
//        aO += 1;
//        bO += 1;
//      }
//    }
//
//    // process unpaired remaining from a
//    while (aO < a.activeLength) {
//      val aI = a.indexAt(aO);
//      a(aI) = op(a.valueAt(aO), b.default);
//      aO += 1;
//    }
//  }
//}
//
///**
// * Base class for updating a SparseArray by another SparseArray.  Considers
// * non-zeros in either operand.  Base class of AddInto.
// *
// * @author dramage
// */
//class SparseArraySparseArrayUpdateEitherNZOp[V1,V2](implicit op : BinaryOp[V1,V2,V1])
//extends BinaryUpdateOp[SparseArray[V1],SparseArray[V2]] {
//  def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
//    if (a.length != b.length) {
//      throw new DomainException(this.getClass.getSimpleName + ": arrays have different lengths");
//    }
//    
//    var aO = 0;
//    var bO = 0;
//    while (aO < a.activeLength && bO < b.activeLength) {
//      val aI = a.indexAt(aO);
//      val bI = b.indexAt(bO);
//      if (aI < bI) {
//        a(aI) = op(a.valueAt(aO), b.default);
//        aO += 1;
//      } else if (bI < aI) {
//        a(bI) = op(a.default, b.valueAt(bO));
//        bO += 1;
//      } else {
//        a(aI) = op(a.valueAt(aO), b.valueAt(bO));
//        aO += 1;
//        bO += 1;
//      }
//    }
//    
//    // process unpaired remaining from a
//    while (aO < a.activeLength) {
//      val aI = a.indexAt(aO);
//      a(aI) = op(a.valueAt(aO), b.default);
//      aO += 1;
//    }
//
//    // process unpaired remaining from b
//    while (bO < b.activeLength) {
//      val bI = b.indexAt(bO);
//      a(bI) = op(a.default, b.valueAt(bO));
//      bO += 1;
//    }
//  }
//}
//
///**
// * Base class for updating a SparseArray by another SparseArray.  Considers
// * all values.  Base class of DivInto.
// *
// * @author dramage
// */
//class SparseArraySparseArrayUpdateAllOp[V1,V2](implicit op : BinaryOp[V1,V2,V1])
//extends BinaryUpdateOp[SparseArray[V1],SparseArray[V2]] {
//  def apply(a : SparseArray[V1], b : SparseArray[V2]) = {
//    if (a.length != b.length) {
//      throw new DomainException(this.getClass.getSimpleName + ": arrays have different lengths");
//    }
//
//    /** Optimization: use OuterOp if the default value is itself default */
//    if (try { op(a.default, b.default) == a.default } catch { case _ => false; }) {
//      (new SparseArraySparseArrayUpdateEitherNZOp[V1,V2]).apply(a,b);
//    } else {
//      var i = 0;
//      while (i < a.length) {
//        a(i) = op(a(i),b(i));
//        i += 1;
//      }
//    }
//  }
//}
//
//class SparseArrayScalarUpdateOp[V1,B](implicit op : BinaryOp[V1,B,V1], sb : Scalar[B])
//extends BinaryUpdateOp[SparseArray[V1],B] {
//  def apply(a : SparseArray[V1], b : B) =
//    a.transform(v => op(v, b));
//}
}


/**
 * Default value of type T as used by SparseArray.
 * 
 * Note that this is not the same as a general default value for T,
 * say as used by DomainMap, because this value must be null for
 * all references types in order for SparseArray to work as expected.
 * 
 * @author dramage
 */
sealed trait DefaultArrayValue[@specialized T] extends Serializable {
  def value : T;
}

object DefaultArrayValue {
  implicit object IntDefaultArrayValue extends DefaultArrayValue[Int] {
    override def value = 0;
  }

  implicit object ShortDefaultArrayValue extends DefaultArrayValue[Short] {
    override def value = 0.toShort;
  }

  implicit object LongDefaultArrayValue extends DefaultArrayValue[Long] {
    override def value = 0l;
  }

  implicit object ByteDefaultArrayValue extends DefaultArrayValue[Byte] {
    override def value = 0.toByte;
  }

  implicit object CharDefaultArrayValue extends DefaultArrayValue[Char] {
    override def value = 0.toChar;
  }

  implicit object FloatDefaultArrayValue extends DefaultArrayValue[Float] {
    override def value = 0.0f;
  }

  implicit object DoubleDefaultArrayValue extends DefaultArrayValue[Double] {
    override def value = 0.0;
  }

  implicit object BooleanDefaultArrayValue extends DefaultArrayValue[Boolean] {
    override def value = false;
  }

  val refDefault = new DefaultArrayValue[AnyRef] {
    override def value : AnyRef = null;
  }

  implicit def ObjectDefaultArrayValue[T<:AnyRef] =
    refDefault.asInstanceOf[DefaultArrayValue[T]];
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanAppendColumns.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.scalar._;
import scalala.tensor.domain.DomainException;
import scalala.collection.sparse.{SparseArray,DefaultArrayValue};

/**
 * Construction delegate for appending columns with A | B.
 *
 * @author dramage
 */
trait CanAppendColumns[A,-B,+That] extends Function2[A,B,That];



================================================
FILE: src/main/scala/scalala/generic/collection/CanBuildTensorForBinaryOp.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.tensor.domain.CanGetDomain;
import scalala.tensor.generic.TensorBuilder;
import scalala.tensor.Tensor;

/**
 * Trait for building a new tensor from either A or B depending on the
 * given Op.  Default to building tensor for left operand.
 *
 * @author dramage
 */
trait CanBuildTensorForBinaryOp[-A, -B, D, K, V, Op, +To] {
  def apply(a : A, b : B, domain : D) : TensorBuilder[K,V,To];
}

object CanBuildTensorForBinaryOp {
  implicit def canBuildTensorLeft[A,B,D,K,V,Op,To]
  (implicit va : A=>Tensor[_,_], bf : CanBuildTensorFrom[A,D,K,V,To])
  : CanBuildTensorForBinaryOp[A,B,D,K,V,Op,To]
  = new CanBuildTensorForBinaryOp[A,B,D,K,V,Op,To] {
    def apply(a : A, b : B, domain : D)  = bf.apply(a, domain);
  }
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanBuildTensorFrom.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.tensor._;
import scalala.tensor.domain._;
import scalala.tensor.dense._;
import scalala.tensor.generic.TensorBuilder;
import scalala.scalar.Scalar;

/**
 * Trait for constructing a lazy view of a given Tensor.
 *
 * @author dramage
 */
trait CanBuildTensorFrom[-From, -Domain, K, V, +To] {
  def apply(from : From, domain : Domain) : TensorBuilder[K,V,To];
}

/**
 * Base level implicits take any tensor and any domain.
 *
 * @author dramage
 */
trait CanBuildTensorFromImplicitsLevel0 {
  implicit def canBuildTensorFromTensor[K,V:Scalar]
  : CanBuildTensorFrom[Tensor[_,_], IterableDomain[K], K, V, mutable.Tensor[K,V]]
  = new CanBuildTensorFrom[Tensor[_,_], IterableDomain[K], K, V, mutable.Tensor[K,V]] {
    override def apply(from : Tensor[_,_], domain : IterableDomain[K]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Tensor[K,V]]];
  }
}

/**
 * Implicits that take any shaped tensor (Tensor1Row, Tensor1Col, Tensor2)
 * and a shaped domain and return a similarly shaped tensor.
 *
 * @author dramage
 */
trait CanBuildTensorFromImplicitsLevel1 extends CanBuildTensorFromImplicitsLevel0 {
  implicit def canBuildTensor1RowFromTensor1Row[K,V:Scalar]
  : CanBuildTensorFrom[Tensor1Row[_,_], Domain1[K], K, V, mutable.Tensor1Row[K,V]]
  = new CanBuildTensorFrom[Tensor1Row[_,_], Domain1[K], K, V, mutable.Tensor1Row[K,V]] {
    override def apply(from : Tensor1Row[_,_], domain : Domain1[K]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Tensor1Row[K,V]]];
  }
  
  implicit def canBuildTensor1ColFromTensor1Row[K,V:Scalar]
  : CanBuildTensorFrom[Tensor1Col[_,_], Domain1[K], K, V, mutable.Tensor1Col[K,V]]
  = new CanBuildTensorFrom[Tensor1Col[_,_], Domain1[K], K, V, mutable.Tensor1Col[K,V]] {
    override def apply(from : Tensor1Col[_,_], domain : Domain1[K]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Tensor1Col[K,V]]];
  }

  implicit def canBuildTensor2FromTensor[K1,K2,V:Scalar]
  : CanBuildTensorFrom[Tensor[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Tensor2[K1,K2,V]]
  = new CanBuildTensorFrom[Tensor[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Tensor2[K1,K2,V]] {
    override def apply(from : Tensor[_,_], domain : Domain2[K1,K2]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[(K1,K2),V,mutable.Tensor2[K1,K2,V]]];
  }
}

/**
 * Implicits that take any tensor and a vector/matrix domain and return a
 * vector or matrix.
 *
 * @author dramage
 */
trait CanBuildTensorFromImplicitsLevel2 extends CanBuildTensorFromImplicitsLevel1 {
  implicit def canBuildVectorColFromTensor[V:Scalar]
  : CanBuildTensorFrom[Tensor[_,_], IndexDomain, Int, V, mutable.VectorCol[V]]
  = new CanBuildTensorFrom[Tensor[_,_], IndexDomain, Int, V, mutable.VectorCol[V]] {
    override def apply(from : Tensor[_,_], domain : IndexDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,mutable.VectorCol[V]]];
  }
  
  implicit def canBuildMatrixFromTensor[V:Scalar]
  : CanBuildTensorFrom[Tensor[_,_], TableDomain, (Int,Int), V, mutable.Matrix[V]]
  = new CanBuildTensorFrom[Tensor[_,_], TableDomain, (Int,Int), V, mutable.Matrix[V]] {
    override def apply(from : Tensor[_,_], domain : TableDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[(Int,Int),V,mutable.Matrix[V]]];
  }
}

/**
 * Keep row shape in Level 2.
 *
 * @author dramage
 */
trait CanBuildTensorFromImplicitsLevel2Row extends CanBuildTensorFromImplicitsLevel2 {
  implicit def canBuildVectorRowFromTensor1Row[V:Scalar]
  : CanBuildTensorFrom[Tensor1Row[_,_], IndexDomain, Int, V, mutable.VectorRow[V]]
  = new CanBuildTensorFrom[Tensor1Row[_,_], IndexDomain, Int, V, mutable.VectorRow[V]] {
    override def apply(from : Tensor1Row[_,_], domain : IndexDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,mutable.VectorRow[V]]];
  }
}

/**
 * Implicits that keep the type and shape of common input vectors and matrices.
 *
 * @author dramage
 */
trait CanBuildTensorFromImplicitsLevel3 extends CanBuildTensorFromImplicitsLevel2Row {
  import dense._;
  import sparse._;
  import tensor.{Counter,Counter2};

  implicit def canBuildCounterFromCounter[K,V:Scalar]
  : CanBuildTensorFrom[Counter[_,_], Domain1[K], K, V, mutable.Counter[K,V]]
  = new CanBuildTensorFrom[Counter[_,_], Domain1[K], K, V, mutable.Counter[K,V]] {
    override def apply(from : Counter[_,_], domain : Domain1[K]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Counter[K,V]]];
  }
  
  implicit def canBuildCounter2FromCounter2[K1,K2,V:Scalar]
  : CanBuildTensorFrom[Counter2[_,_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]]
  = new CanBuildTensorFrom[Counter2[_,_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]] {
    override def apply(from : Counter2[_,_,_], domain : Domain2[K1,K2]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[(K1,K2),V,mutable.Counter2[K1,K2,V]]];
  }
  
  implicit def canBuildCounterFromCounter2[K,V:Scalar]
  : CanBuildTensorFrom[Counter2[_,_,_], Domain1[K], K, V, mutable.Counter[K,V]]
  = new CanBuildTensorFrom[Counter2[_,_,_], Domain1[K], K, V, mutable.Counter[K,V]] {
    override def apply(from : Counter2[_,_,_], domain : Domain1[K]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[K,V,mutable.Counter[K,V]]];
  }
  
  implicit def canBuildCounter2FromCounter[K1,K2,V:Scalar]
  : CanBuildTensorFrom[Counter[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]]
  = new CanBuildTensorFrom[Counter[_,_], Domain2[K1,K2], (K1,K2), V, mutable.Counter2[K1,K2,V]] {
    override def apply(from : Counter[_,_], domain : Domain2[K1,K2]) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[(K1,K2),V,mutable.Counter2[K1,K2,V]]];
  }
  
  implicit def canBuildDenseVectorColFromDenseTensor[V:Scalar]
  : CanBuildTensorFrom[DenseArrayTensor[_,_], IndexDomain, Int, V, DenseVectorCol[V]]
  = new CanBuildTensorFrom[DenseArrayTensor[_,_], IndexDomain, Int, V, DenseVectorCol[V]] {
    override def apply(from : DenseArrayTensor[_,_], domain : IndexDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,DenseVectorCol[V]]];
  }
  
  implicit def canBuildDenseMatrixFromDenseTensor[V:Scalar]
  : CanBuildTensorFrom[DenseArrayTensor[_,_], TableDomain, (Int,Int), V, DenseMatrix[V]]
  = new CanBuildTensorFrom[DenseArrayTensor[_,_], TableDomain, (Int,Int), V, DenseMatrix[V]] {
    override def apply(from : DenseArrayTensor[_,_], domain : TableDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[(Int,Int),V,DenseMatrix[V]]];
  }
  
  implicit def canBuildSparseVectorColFromSparseTensor[V:Scalar]
  : CanBuildTensorFrom[SparseArrayTensor[_,_], IndexDomain, Int, V, SparseVectorCol[V]]
  = new CanBuildTensorFrom[SparseArrayTensor[_,_], IndexDomain, Int, V, SparseVectorCol[V]] {
    override def apply(from : SparseArrayTensor[_,_], domain : IndexDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,SparseVectorCol[V]]];
  }
}

/**
 * Keep row shape in Level 3.
 *
 * @author dramage
 */
trait CanBuildTensorFromImplicitsLevel3Row extends CanBuildTensorFromImplicitsLevel3 {
  import dense._;
  import sparse._;

  implicit def canBuildDenseVectorRowFromDenseVectorRow[V:Scalar]
  : CanBuildTensorFrom[DenseVectorRow[_], IndexDomain, Int, V, DenseVectorRow[V]]
  = new CanBuildTensorFrom[DenseVectorRow[_], IndexDomain, Int, V, DenseVectorRow[V]] {
    override def apply(from : DenseVectorRow[_], domain : IndexDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,DenseVectorRow[V]]];
  }

  implicit def canBuildSparseVectorRowFromSparseVectorRow[V:Scalar]
  : CanBuildTensorFrom[SparseVectorRow[_], IndexDomain, Int, V, SparseVectorRow[V]]
  = new CanBuildTensorFrom[SparseVectorRow[_], IndexDomain, Int, V, SparseVectorRow[V]] {
    override def apply(from : SparseVectorRow[_], domain : IndexDomain) =
      from.newBuilder(domain).asInstanceOf[TensorBuilder[Int,V,SparseVectorRow[V]]];
  }
}

object CanBuildTensorFrom extends CanBuildTensorFromImplicitsLevel3Row;



================================================
FILE: src/main/scala/scalala/generic/collection/CanCopy.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;


import scalala.scalar.Scalar;

/**
 * Marker for being able to copy a collection
 *
 * @author dlwh
 */
trait CanCopy[T] {
  // Should not inherit from T=>T because those get  used by the compiler.
  def apply(t: T):T
}

object CanCopy {

  class OpArray[@specialized V:ClassManifest:Scalar]
  extends CanCreateZerosLike[Array[V],Array[V]] {
    override def apply(from : Array[V]) = {
      Array.fill(from.length)(implicitly[Scalar[V]].zero);
    }
  }

  class OpMapValues[From,A](implicit op : CanCopy[A], map : CanMapValues[From,A,A,From]) extends CanCopy[From] {
    def apply(v : From) = map.map(v, op.apply(_));
  }

  implicit def opMapValues[From,A](implicit map : CanMapValues[From,A,A,From], op : CanCopy[A])
  : CanCopy[From] = new OpMapValues[From,A]()(op, map);

  implicit def OpArrayAny[V:ClassManifest:Scalar] : OpArray[V] =
    new OpArray[V];

  implicit object OpArrayI extends OpArray[Int];
  implicit object OpArrayS extends OpArray[Short];
  implicit object OpArrayL extends OpArray[Long];
  implicit object OpArrayF extends OpArray[Float];
  implicit object OpArrayD extends OpArray[Double];

  implicit def canCopyScalar[V:Scalar]:CanCopy[V] = new CanCopy[V] {
    def apply(v1: V) = v1;
  }
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanCreateZerosLike.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.collection.sparse.{SparseArray,DefaultArrayValue};
import scalala.scalar.Scalar;

/**
 * Marker for being able to create a collection of the same shape as
 * the given input but with zero values everywhere.
 *
 * @author dramage
 */
trait CanCreateZerosLike[-From, +To] {
  // Should not inherit from Form=>To because the compiler will try to use it to coerce types.
  def apply(from: From):To
};

object CanCreateZerosLike {

  class OpArray[@specialized V:ClassManifest:Scalar]
  extends CanCreateZerosLike[Array[V],Array[V]] {
    override def apply(from : Array[V]) = {
      Array.fill(from.length)(implicitly[Scalar[V]].zero);
    }
  }

  class OpMapValues[From,A,To](implicit op : Scalar[A], map : CanMapValues[From,A,A,To]) extends CanCreateZerosLike[From,To] {
    def apply(v : From) = map.map(v, _ => op.zero);
  }

  implicit def opMapValues[From,A,To](implicit map : CanMapValues[From,A,A,To], op : Scalar[A])
  : CanCreateZerosLike[From,To] = new OpMapValues[From,A,To]()(op, map);

  implicit def OpArrayAny[V:ClassManifest:Scalar] : OpArray[V] =
    new OpArray[V];

  implicit object OpArrayI extends OpArray[Int];
  implicit object OpArrayS extends OpArray[Short];
  implicit object OpArrayL extends OpArray[Long];
  implicit object OpArrayF extends OpArray[Float];
  implicit object OpArrayD extends OpArray[Double];
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanFilterValues.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.collection.sparse.{SparseArray,DefaultArrayValue};

/**
 * Marker for being able to filter the values in a value collection.
 *
 * @author dramage
 */
trait CanFilterValues[From, @specialized A, +To] {
  /** Maps all values from the given collection. */
  def filter(from : From, fn : (A=>Boolean)) : To;

  /** Maps all non-zero values from the given collection. */
  def filterNonZero(from : From, fn : (A=>Boolean)) : To;
}

object CanFilterValues {
  type Op[From,A,To] = CanFilterValues[From,A,To];

  //
  // Arrays
  //

  class OpArray[@specialized A:ClassManifest]
  extends Op[Array[A],A,Array[A]] {
    def filter(from : Array[A], fn : (A=>Boolean)) =
      from.filter(fn);
    def filterNonZero(from : Array[A], fn : (A => Boolean)) =
      this.filter(from, fn);
  }

  implicit def opArray[@specialized A:ClassManifest] =
    new OpArray[A];

  implicit object OpArrayI extends OpArray[Int];
  implicit object OpArrayS extends OpArray[Short];
  implicit object OpArrayL extends OpArray[Long];
  implicit object OpArrayF extends OpArray[Float];
  implicit object OpArrayD extends OpArray[Double];

  //
  // SparseArrays
  //
  class OpSparseArray[@specialized V:ClassManifest:DefaultArrayValue]
  extends Op[SparseArray[V],V,SparseArray[V]] {
    def filter(from : SparseArray[V], fn : (V=>Boolean)) =
      from.filter(fn);

    def filterNonZero(from : SparseArray[V], fn : (V=>Boolean)) = {
      val rv = new SparseArray[V](from.length, from.activeLength);
      from.foreachActivePair((k,v) => if (fn(v)) { rv(k) = v; });
      rv.compact;
      rv;
    }
  }

  implicit def opSparseArray[@specialized V:ClassManifest:DefaultArrayValue] =
    new OpSparseArray[V];

  implicit object OpSparseArrayI extends OpSparseArray[Int];
  implicit object OpSparseArrayS extends OpSparseArray[Short];
  implicit object OpSparseArrayL extends OpSparseArray[Long];
  implicit object OpSparseArrayF extends OpSparseArray[Float];
  implicit object OpSparseArrayD extends OpSparseArray[Double];


  //
  // Scala maps
  //

  implicit def opMap[A, B, That](implicit bf : scala.collection.generic.CanBuildFrom[scala.collection.Map[A,B], (A,B), That]) =
    new OpMap[A,B,That];

  class OpMap[A, B, That] extends Op[scala.collection.Map[A,B],B,scala.collection.Map[A,B]] {
    def filter(from : scala.collection.Map[A,B], fn : (B => Boolean)) =
      from.filter((tup : (A,B)) => fn(tup._2));
    def filterNonZero(from : scala.collection.Map[A,B], fn : (B => Boolean)) =
      this.filter(from, fn);
  }
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanGetActiveValues.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.collection.sparse.SparseArray;

/**
 * Marker for being able to get the domain (keys) of a collection.
 *
 * @author dramage
 */
trait CanGetActiveValues[-Coll, @specialized(Int,Long) K, @specialized(Int,Long,Float,Double) V] {
  def apply(coll : Coll) : Iterator[(K,V)];
}

object CanGetActiveValues {
  class OpArray[V] extends CanGetActiveValues[Array[V],Int,V] {
    override def apply(coll : Array[V]) =
      Iterator.range(0, coll.length).map(i => (i, coll(i)));
  }

  implicit def opArray[V] = new OpArray[V];

  implicit object OpArrayI extends OpArray[Int];
  implicit object OpArrayS extends OpArray[Short];
  implicit object OpArrayL extends OpArray[Long];
  implicit object OpArrayF extends OpArray[Float];
  implicit object OpArrayD extends OpArray[Double];

  class OpSparseArray[V] extends CanGetActiveValues[SparseArray[V],Int,V] {
    override def apply(coll : SparseArray[V]) =
      coll.activeIterator;
  }

  implicit def opSparseArray[V] = new OpSparseArray[V];
  
  implicit object OpSparseArrayI extends OpSparseArray[Int];
  implicit object OpSparseArrayS extends OpSparseArray[Short];
  implicit object OpSparseArrayL extends OpSparseArray[Long];
  implicit object OpSparseArrayF extends OpSparseArray[Float];
  implicit object OpSparseArrayD extends OpSparseArray[Double];
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanGetDouble.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Marker for being able to get the value of a map at a key as a double.
 *
 * @author dramage
 */
trait CanGetDouble[-Coll, @specialized(Int,Long) -K] {
  def apply(coll : Coll, key : K) : Double;
}

object CanGetDouble {
  type Op[Coll,K] = CanGetDouble[Coll,K];

  implicit object OpArrayI extends Op[Array[Int],Int]
  { override def apply(coll : Array[Int], key : Int) = coll(key); }

  implicit object OpArrayS extends Op[Array[Short],Int]
  { override def apply(coll : Array[Short], key : Int) = coll(key); }

  implicit object OpArrayL extends Op[Array[Long],Int]
  { override def apply(coll : Array[Long], key : Int) = coll(key); }

  implicit object OpArrayF extends Op[Array[Float],Int]
  { override def apply(coll : Array[Float], key : Int) = coll(key); }

  implicit object OpArrayD extends Op[Array[Double],Int]
  { override def apply(coll : Array[Double], key : Int) = coll(key); }

  implicit def opIndexedSeq[@specialized V](implicit cv : V => Double) =
    new OpIndexedSeq[V];

  class OpIndexedSeq[@specialized V](implicit cv : V => Double) extends CanGetDouble[IndexedSeq[V], Int] {
    def apply(coll : IndexedSeq[V], key : Int) = coll(key);
  }

  implicit object OpIndexedSeqI extends OpIndexedSeq[Int];
  implicit object OpIndexedSeqC extends OpIndexedSeq[Char];
  implicit object OpIndexedSeqS extends OpIndexedSeq[Short];
  implicit object OpIndexedSeqL extends OpIndexedSeq[Long];
  implicit object OpIndexedSeqF extends OpIndexedSeq[Float];
  implicit object OpIndexedSeqD extends OpIndexedSeq[Double];

  implicit def opMap[K,V](implicit cv : V => Double) =
    new OpMap[K,V];

  class OpMap[K,V](implicit cv : V => Double) extends CanGetDouble[scala.collection.Map[K,V], K] {
    def apply(coll : scala.collection.Map[K,V], key : K) = coll(key);
  }
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanGetValue.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Marker for being able to get the value of a map at a key.
 *
 * @author dramage
 */
trait CanGetValue[-Coll, @specialized(Int,Long) -K, @specialized(Int,Long,Float,Double) +V] {
  def apply(coll : Coll, key : K) : V;
}

object CanGetValue {
  implicit def opArray[@specialized V] =
    new OpArray[V];

  class OpArray[@specialized V] extends CanGetValue[Array[V], Int, V] {
    def apply(coll : Array[V], key : Int) = coll(key);
  }

  implicit object OpArrayI extends OpArray[Int];
  implicit object OpArrayC extends OpArray[Char];
  implicit object OpArrayS extends OpArray[Short];
  implicit object OpArrayL extends OpArray[Long];
  implicit object OpArrayF extends OpArray[Float];
  implicit object OpArrayD extends OpArray[Double];
  implicit object OpArrayB extends OpArray[Boolean];

  implicit def opIndexedSeq[@specialized V] =
    new OpIndexedSeq[V];

  class OpIndexedSeq[@specialized V] extends CanGetValue[IndexedSeq[V], Int, V] {
    def apply(coll : IndexedSeq[V], key : Int) = coll(key);
  }

  implicit object OpIndexedSeqI extends OpIndexedSeq[Int];
  implicit object OpIndexedSeqC extends OpIndexedSeq[Char];
  implicit object OpIndexedSeqS extends OpIndexedSeq[Short];
  implicit object OpIndexedSeqL extends OpIndexedSeq[Long];
  implicit object OpIndexedSeqF extends OpIndexedSeq[Float];
  implicit object OpIndexedSeqD extends OpIndexedSeq[Double];
  implicit object OpIndexedSeqB extends OpIndexedSeq[Boolean];

  implicit def opMap[K,V] =
    new OpMap[K,V];

  class OpMap[K,V] extends CanGetValue[scala.collection.Map[K,V], K, V] {
    def apply(coll : scala.collection.Map[K,V], key : K) = coll(key);
  }
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanJoin.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Trait for applying a function to two tensors across their underlying
 * shared keys -- either all keys or non-zero keys.  The tensors must
 * have the same domain.
 *
 * @author dramage
 */
trait CanJoin[-A, -B, @specialized(Int,Long) K,
              @specialized(Int,Long,Float,Double) V1,
              @specialized(Int,Long,Float,Double) V2] {
  /** Joins on all keys in the domain. */
  def joinAll[RV](a : A, b : B, fn : (K,V1,V2)=>RV) : Unit;

  /** Joins when both a and b are non-zero. */
  def joinBothNonZero[RV](a : A, b : B, fn : (K,V1,V2)=>RV) : Unit;

  /** Joins when either a or b is non-zero. */
  def joinEitherNonZero[RV](a : A, b : B, fn : (K,V1,V2)=>RV) : Unit;
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanMapKeyValuePairs.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Marker for being able to map the keys and values in a value collection
 * to new values.
 *
 * @author dramage
 */
trait CanMapKeyValuePairs[-From, +K, +A, -B, +To] {
  /** Maps all key-value pairs from the given collection. */
  def map(from : From, fn : ((K,A) => B)) : To;

  /** Maps all non-zero key-value pairs from the given collection. */
  def mapNonZero(from : From, fn : ((K,A) => B)) : To;
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanMapValues.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.scalar.Complex
import scalala.collection.sparse.{SparseArray,DefaultArrayValue};

/**
 * Marker for being able to map the values in a value collection.
 *
 * @author dramage
 */
trait CanMapValues[From, @specialized A, @specialized B, +To] {
  /** Maps all values from the given collection. */
  def map(from : From, fn : (A=>B)) : To;

  /** Maps all non-zero values from the given collection. */
  def mapNonZero(from : From, fn : (A=>B)) : To;
}

object CanMapValues {
  type Op[From,A,B,To] = CanMapValues[From,A,B,To];

  //
  // Arrays
  //

  class OpArray[@specialized A, @specialized B:ClassManifest]
  extends Op[Array[A],A,B,Array[B]] {
    def map(from : Array[A], fn : (A=>B)) =
      from.map(fn);
    def mapNonZero(from : Array[A], fn : (A => B)) =
      this.map(from, fn);
  }

  implicit def opArray[@specialized A, @specialized B:ClassManifest] =
    new OpArray[A,B];

  implicit object OpArrayII extends OpArray[Int,Int];
  implicit object OpArraySS extends OpArray[Short,Short];
  implicit object OpArrayLL extends OpArray[Long,Long];
  implicit object OpArrayFF extends OpArray[Float,Float];
  implicit object OpArrayDD extends OpArray[Double,Double];
  implicit object OpArrayCC extends OpArray[Complex,Complex];
  implicit object OpArrayID extends OpArray[Int,Double];
  implicit object OpArraySD extends OpArray[Short,Double];
  implicit object OpArrayLD extends OpArray[Long,Double];
  implicit object OpArrayFD extends OpArray[Float,Double];

  //
  // SparseArrays
  //

  class OpSparseArray[@specialized V, @specialized RV:ClassManifest:DefaultArrayValue]
  extends Op[SparseArray[V],V,RV,SparseArray[RV]] {
    def map(from : SparseArray[V], fn : (V=>RV)) =
      from.map(fn);

    def mapNonZero(from : SparseArray[V], fn : (V => RV)) = {
      val rv = new SparseArray[RV](from.length, from.activeLength);
      from.foreachActivePair((k,v) => rv(k) = fn(v));
      rv;
    }
  }

  implicit def opSparseArray[@specialized V, @specialized RV:ClassManifest:DefaultArrayValue] =
    new OpSparseArray[V,RV];

  implicit object OpSparseArrayII extends OpSparseArray[Int,Int];
  implicit object OpSparseArraySS extends OpSparseArray[Short,Short];
  implicit object OpSparseArrayLL extends OpSparseArray[Long,Long];
  implicit object OpSparseArrayFF extends OpSparseArray[Float,Float];
  implicit object OpSparseArrayDD extends OpSparseArray[Double,Double];
  implicit object OpSparseArrayCC extends OpSparseArray[Complex,Complex];
  implicit object OpSparseArrayID extends OpSparseArray[Int,Double];
  implicit object OpSparseArraySD extends OpSparseArray[Short,Double];
  implicit object OpSparseArrayLD extends OpSparseArray[Long,Double];
  implicit object OpSparseArrayFD extends OpSparseArray[Float,Double];

  //
  // Scala maps
  //

  implicit def opMap[A, B, O, That](implicit bf : scala.collection.generic.CanBuildFrom[scala.collection.Map[A,B], (A,O), That]) =
    new OpMap[A,B,O,That];

  class OpMap[K, A, B, That](implicit bf : scala.collection.generic.CanBuildFrom[scala.collection.Map[K,A], (K,B), That])
  extends Op[scala.collection.Map[K,A],A,B,That] {
    def map(from : scala.collection.Map[K,A], fn : (A => B)) =
      from.map(tup => (tup._1, fn(tup._2)));
    def mapNonZero(from : scala.collection.Map[K,A], fn : (A => B)) =
      this.map(from, fn);
  }
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanSliceMatrix.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Builder trait for a slicing a view of a matrix.
 *
 * @author dramage
 */
trait CanSliceMatrix[-From, A1, A2, +To] {
  def apply(from : From, keys1 : Seq[A1], keys2 : Seq[A2]) : To;
}


/**
 * Builder trait for a slicing a row from a matrix.
 *
 * @author dramage
 */
trait CanSliceRow[-From, K, +To] {
  def apply(from : From, row : K) : To;
}


/**
 * Builder trait for a slicing a column from a matrix.
 *
 * @author dramage
 */
trait CanSliceCol[-From, K, +To] {
  def apply(from : From, col : K) : To;
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanSliceTensor.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Supports sliced view of a Tensor.
 *
 * @author dramage
 */
trait CanSliceTensor[-From, A1, A2, +To] {
  def apply(from : From, keymap : scala.collection.Map[A2,A1]) : To;
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanSliceVector.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Capability trait for slicing a Vector from something.
 *
 * @author dramage
 */
trait CanSliceVector[-From, A, +To] {
  def apply(from : From, keys : Seq[A]) : To;
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanTranspose.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */

package scalala;
package operators;

import scalala.tensor._;

/**
 * Transpose of a shaped value.
 *
 * @author dramage
 */
trait CanTranspose[-From,+To] extends (From=>To);

/**
 * Transpose non-mutable tensors.
 * 
 * @author dramage
 */
trait CanTransposeImplicitsLevel0 {
  implicit def canTransposeTensor1Row[K,V]
  : CanTranspose[Tensor1Row[K,V],Tensor1Col[K,V]]
  = new CanTranspose[Tensor1Row[K,V],Tensor1Col[K,V]] {
    override def apply(from : Tensor1Row[K,V]) =
      from.t;
  }

  implicit def canTransposeTensor1Col[K,V]
  : CanTranspose[Tensor1Col[K,V],Tensor1Row[K,V]]
  = new CanTranspose[Tensor1Col[K,V],Tensor1Row[K,V]] {
    override def apply(from : Tensor1Col[K,V]) =
      from.t;
  }
  
  implicit def canTransposeTensor2[K2,K1,V]
  : CanTranspose[Tensor2[K1,K2,V],Tensor2[K2,K1,V]]
  = new CanTranspose[Tensor2[K1,K2,V],Tensor2[K2,K1,V]] {
    override def apply(from : Tensor2[K1,K2,V]) = {
      from.t;
    }
  }
}

trait CanTransposeImplicitsLevel0M extends CanTransposeImplicitsLevel0 {
  implicit def canTransposeMutableTensor1Col[K,V]
  : CanTranspose[mutable.Tensor1Col[K,V],mutable.Tensor1Row[K,V]]
  = new CanTranspose[mutable.Tensor1Col[K,V],mutable.Tensor1Row[K,V]] {
    override def apply(from : mutable.Tensor1Col[K,V]) =
      from.t;
  }
  
  implicit def canTransposeMutableTensor1Row[K,V]
  : CanTranspose[mutable.Tensor1Row[K,V],mutable.Tensor1Col[K,V]]
  = new CanTranspose[mutable.Tensor1Row[K,V],mutable.Tensor1Col[K,V]] {
    override def apply(from : mutable.Tensor1Row[K,V]) =
      from.t;
  }
}

trait CanTransposeImplicitsLevel1 extends CanTransposeImplicitsLevel0M {
  implicit def canTransposeVectorRow[V] : CanTranspose[VectorRow[V],VectorCol[V]]
  = new CanTranspose[VectorRow[V],VectorCol[V]] {
    override def apply(from : VectorRow[V]) =
      from.t;
  }

  implicit def canTransposeVectorCol[V] : CanTranspose[VectorCol[V],VectorRow[V]]
  = new CanTranspose[VectorCol[V],VectorRow[V]] {
    override def apply(from : VectorCol[V]) =
      from.t;
  }
  
  implicit def canTransposeMatrix[V] : CanTranspose[Matrix[V],Matrix[V]] =
  new CanTranspose[Matrix[V],Matrix[V]] {
    override def apply(from : Matrix[V]) =
      from.t;
  }
}

trait CanTransposeImplicitsLevel1M extends CanTransposeImplicitsLevel1 {
  implicit def canTransposeMutableVectorCol[V]
  : CanTranspose[mutable.VectorCol[V],mutable.VectorRow[V]]
  = new CanTranspose[mutable.VectorCol[V],mutable.VectorRow[V]] {
    override def apply(from : mutable.VectorCol[V]) =
      from.t;
  }
  
  implicit def canTransposeMutableVectorRow[V]
  : CanTranspose[mutable.VectorRow[V],mutable.VectorCol[V]]
  = new CanTranspose[mutable.VectorRow[V],mutable.VectorCol[V]] {
    override def apply(from : mutable.VectorRow[V]) =
      from.t;
  }
  
  implicit def canTransposeMutableMatrix[V] : CanTranspose[mutable.Matrix[V],mutable.Matrix[V]] =
  new CanTranspose[mutable.Matrix[V],mutable.Matrix[V]] {
    override def apply(from : mutable.Matrix[V]) =
      from.t;
  }
}

trait CanTransposeImplicitsLevel2 {
  implicit def canTransposeSparseVectorRow[V] : CanTranspose[sparse.SparseVectorRow[V],sparse.SparseVectorCol[V]]
  = new CanTranspose[sparse.SparseVectorRow[V],sparse.SparseVectorCol[V]] {
    override def apply(from : sparse.SparseVectorRow[V]) =
      from.t;
  }
  
  implicit def canTransposeSparseVectorCol[V] : CanTranspose[sparse.SparseVectorCol[V],sparse.SparseVectorRow[V]]
  = new CanTranspose[sparse.SparseVectorCol[V],sparse.SparseVectorRow[V]] {
    override def apply(from : sparse.SparseVectorCol[V]) =
      from.t;
  }
  
  implicit def canTransposeDenseVectorRow[V] : CanTranspose[dense.DenseVectorRow[V],dense.DenseVectorCol[V]]
  = new CanTranspose[dense.DenseVectorRow[V],dense.DenseVectorCol[V]] {
    override def apply(from : dense.DenseVectorRow[V]) =
      from.t;
  }
  
  implicit def canTransposeDenseVectorCol[V] : CanTranspose[dense.DenseVectorCol[V],dense.DenseVectorRow[V]]
  = new CanTranspose[dense.DenseVectorCol[V],dense.DenseVectorRow[V]] {
    override def apply(from : dense.DenseVectorCol[V]) =
      from.t;
  }
}

object CanTranspose extends CanTransposeImplicitsLevel2 {
  
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanView.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

/**
 * Trait for constructing a lazy view of a given Tensor.
 *
 * @author dramage
 */
trait CanView[-From, +To] {
  def apply(from : From) : To;
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanViewAsTensor1.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.collection.sparse.SparseArray;

import scalala.scalar.Scalar;
import scalala.tensor.Tensor1;
import scalala.tensor.dense.DenseVectorCol;
import scalala.tensor.sparse.SparseVectorCol;

/**
 * View something as a Tensor1.
 *
 * @author dramage
 */
trait CanViewAsTensor1[-From,K,V] {
  def apply(from : From) : Tensor1[K,V];
}

object CanViewAsTensor1 {
  //
  // View arrays
  //

  class ArrayTensor1[V:ClassManifest:Scalar]
  extends CanViewAsTensor1[Array[V],Int,V] {
    def apply(from : Array[V]) = new DenseVectorCol[V](from);
  }

  implicit def mkArrayTensor1[V:ClassManifest:Scalar] =
    new ArrayTensor1[V]();

  implicit object ArrayI extends ArrayTensor1[Int];
  implicit object ArrayS extends ArrayTensor1[Short];
  implicit object ArrayL extends ArrayTensor1[Long];
  implicit object ArrayF extends ArrayTensor1[Float];
  implicit object ArrayD extends ArrayTensor1[Double];
  implicit object ArrayB extends ArrayTensor1[Boolean];

  //
  // View sparse arrays
  //

  class SparseArrayTensor1[V:ClassManifest:Scalar]
  extends CanViewAsTensor1[SparseArray[V],Int,V] {
    def apply(from : SparseArray[V]) = new SparseVectorCol[V](from);
  }

  implicit def mkSparseArrayTensor1[V:ClassManifest:Scalar] =
    new SparseArrayTensor1[V]();

  implicit object SparseArrayI extends SparseArrayTensor1[Int];
  implicit object SparseArrayS extends SparseArrayTensor1[Short];
  implicit object SparseArrayL extends SparseArrayTensor1[Long];
  implicit object SparseArrayF extends SparseArrayTensor1[Float];
  implicit object SparseArrayD extends SparseArrayTensor1[Double];
  implicit object SparseArrayB extends SparseArrayTensor1[Boolean];

  //
  // View pre-constructed Tensor1 instances
  //

  class Tensor1Tensor1[K,V:Scalar]
  extends CanViewAsTensor1[Tensor1[K,V],K,V] {
    def apply(from : Tensor1[K,V]) = from;
  }

  implicit def mkTensor1Tensor1[K,V:Scalar] =
    new Tensor1Tensor1[K,V]();
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanViewAsTensor2.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.scalar.Scalar;
import scalala.tensor.Tensor2;
import scalala.tensor.dense.ArrayArrayMatrix;

/**
 * View something as a Tensor1.
 *
 * @author dramage
 */
trait CanViewAsTensor2[-From,K1,K2,V] {
  def apply(from : From) : Tensor2[K1,K2,V];
}

object CanViewAsTensor2 {
  //
  // View arrays
  //

  class ArrayArrayTensor2[V:ClassManifest:Scalar]
  extends CanViewAsTensor2[Array[Array[V]],Int,Int,V] {
    def apply(from : Array[Array[V]]) = new ArrayArrayMatrix[V](from);
  }

  implicit def mkArrayArrayTensor2[V:ClassManifest:Scalar] =
    new ArrayArrayTensor2[V]();

  implicit object ArrayArrayI extends ArrayArrayTensor2[Int];
  implicit object ArrayArrayS extends ArrayArrayTensor2[Short];
  implicit object ArrayArrayL extends ArrayArrayTensor2[Long];
  implicit object ArrayArrayF extends ArrayArrayTensor2[Float];
  implicit object ArrayArrayD extends ArrayArrayTensor2[Double];
  implicit object ArrayArrayB extends ArrayArrayTensor2[Boolean];

  //
  // View pre-constructed Tensor2 instances
  //

  class Tensor2Tensor2[K1,K2,V:Scalar]
  extends CanViewAsTensor2[Tensor2[K1,K2,V],K1,K2,V] {
    def apply(from : Tensor2[K1,K2,V]) = from;
  }

  implicit def mkTensor2Tensor2[K1,K2,V:Scalar] =
    new Tensor2Tensor2[K1,K2,V]();
}


================================================
FILE: src/main/scala/scalala/generic/collection/CanViewAsVector.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */
package scalala;
package generic;
package collection;

import scalala.collection.sparse.SparseArray;

import scalala.scalar.Scalar;
import scalala.tensor.Vector;
import scalala.tensor.dense.DenseVectorCol;
import scalala.tensor.sparse.SparseVectorCol;

/**
 * View something as a Vector.
 *
 * @author dramage
 */
trait CanViewAsVector[-From,V] {
  def apply(from : From) : Vector[V];
}

object CanViewAsVector {
  //
  // View arrays
  //

  class ArrayVector[V:ClassManifest:Scalar]
  extends CanViewAsVector[Array[V],V] {
    def apply(from : Array[V]) = new DenseVectorCol[V](from);
  }

  implicit def mkArrayVector[V:ClassManifest:Scalar] =
    new ArrayVector[V]();

  implicit object ArrayI extends ArrayVector[Int];
  implicit object ArrayS extends ArrayVector[Short];
  implicit object ArrayL extends ArrayVector[Long];
  implicit object ArrayF extends ArrayVector[Float];
  implicit object ArrayD extends ArrayVector[Double];
  implicit object ArrayB extends ArrayVector[Boolean];

  //
  // View sparse arrays
  //

  class SparseArrayVector[V:ClassManifest:Scalar]
  extends CanViewAsVector[SparseArray[V],V] {
    def apply(from : SparseArray[V]) = new SparseVectorCol[V](from);
  }

  implicit def mkSparseArrayVector[V:ClassManifest:Scalar] =
    new SparseArrayVector[V]();

  implicit object SparseArrayI extends SparseArrayVector[Int];
  implicit object SparseArrayS extends SparseArrayVector[Short];
  implicit object SparseArrayL extends SparseArrayVector[Long];
  implicit object SparseArrayF extends SparseArrayVector[Float];
  implicit object SparseArrayD extends SparseArrayVector[Double];
  implicit object SparseArrayB extends SparseArrayVector[Boolean];

  //
  // View pre-constructed Vector instances
  //

  class VectorVector[V:Scalar]
  extends CanViewAsVector[Vector[V],V] {
    def apply(from : Vector[V]) = from;
  }

  implicit def mkVectorVector[V:Scalar] =
    new VectorVector[V]();
}



================================================
FILE: src/main/scala/scalala/generic/collection/CanZipMapValues.scala
================================================
package scalala
package generic
package collection

/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */

import scalala.scalar.Complex
import scalala.collection.sparse.{SparseArray, DefaultArrayValue}
import tensor.domain.CanGetDomain
;

/**
 * Marker for being able to zip two From's and map the values to a new collection
 *
 * @author dlwh
 */
trait CanZipMapValues[From, @specialized A, @specialized B, +To] {
  /** Maps all corresponding values from the two collection. */
  def map(from : From, from2: From, fn : (A,A)=>B) : To;
}

object CanZipMapValues {
  type Op[From, A, B, To] = CanZipMapValues[From, A, B, To];

  //
  // Arrays
  //

  class OpArray[@specialized A, @specialized B: ClassManifest]
    extends Op[Array[A], A, B, Array[B]] {

    /**Maps all values from the given collection. */
    def map(from: Array[A], from2: Array[A], fn: (A, A) => B) = {
      require(from.length == from2.length, "Array lengths don't match!")
      val arr = new Array[B](from.length)
      for(i <- 0 until from.length) {
        arr(i) = fn(from(i), from2(i))
      }
      arr
    }

  }


  implicit def opArray[@specialized A, @specialized B: ClassManifest] =
    new OpArray[A, B];

  implicit object OpArrayII extends OpArray[Int, Int];

  implicit object OpArraySS extends OpArray[Short, Short];

  implicit object OpArrayLL extends OpArray[Long, Long];

  implicit object OpArrayFF extends OpArray[Float, Float];

  implicit object OpArrayDD extends OpArray[Double, Double];

  implicit object OpArrayCC extends OpArray[Complex, Complex];

  implicit object OpArrayID extends OpArray[Int, Double];

  implicit object OpArraySD extends OpArray[Short, Double];

  implicit object OpArrayLD extends OpArray[Long, Double];

  implicit object OpArrayFD extends OpArray[Float, Double];

  implicit def canZipMapFromJoin[From,K,V,Domain,V2,To](implicit canJoin: CanJoin[From, From, K, V, V],
                                                        dom: CanGetDomain[From, Domain],
                                                        cbf: CanBuildTensorFrom[From, Domain, K, V2, To]):CanZipMapValues[From, V, V2, To] = {
    new CanZipMapValues[From, V, V2, To] {
      /**Maps all corresponding values from the two collection. */
      def map(from: From, from2: From, fn: (V, V) => V2) = {
        val b = cbf(from, dom(from))
        canJoin.joinAll(from, from2, {(k,v,v2) => b.update(k, fn(v,v2))})
        b.result
      }
    }
  }

}


================================================
FILE: src/main/scala/scalala/generic/math/CanAbs.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */

package scalala;
package generic;
package math;

import scalala.operators.UnaryOp
import collection.CanMapValues


/**
 * Operator type for abs(A).
 *
 * @author dramage
 */
trait OpAbs extends operators.OpType;
object OpAbs extends OpAbs;


/**
 * Construction delegate for abs(A).
 * 
 * @author dlwh
 */
trait CanAbs[-A,+RV] extends UnaryOp[A,OpAbs,RV] {
  def opType = OpAbs;
  def apply(v: A):RV;
}

object CanAbs {
  implicit object OpI extends CanAbs[Int,Double] {
    def apply(v : Int) = scala.math.abs(v);
  }

  implicit object OpL extends CanAbs[Long,Double] {
    def apply(v : Long) = scala.math.abs(v);
  }

  implicit object OpF extends CanAbs[Float,Double] {
    def apply(v : Float) = scala.math.abs(v);
  }

  implicit object OpD extends CanAbs[Double,Double] {
    def apply(v : Double) = scala.math.abs(v);
  }

  class OpMapValues[From,A,B,To](implicit op : CanAbs[A,B], map : CanMapValues[From,A,B,To]) extends CanAbs[From,To] {
    def apply(v : From) = map.map(v, op.apply(_));
  }

  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanAbs[A,B])
  : CanAbs[From,To] = new OpMapValues[From,A,B,To]()(op, map);

  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);
  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);
  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);
  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);
}

================================================
FILE: src/main/scala/scalala/generic/math/CanExp.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */

package scalala;
package generic;
package math;

import collection.CanMapValues;

import scalala.operators.{UnaryOp}
import scalala.scalar.Complex
import scalala.tensor.{Matrix, Vector}

/**
 * Operator type for exp(A).
 *
 * @author dramage
 */
trait OpExp extends operators.OpType;
object OpExp extends OpExp;

/**
 * Constructiond delegate for exp(A).
 *
 * @author dramage
 */
trait CanExp[A,+RV] extends UnaryOp[A,OpExp,RV] {
  def opType = OpExp;
}

object CanExp {
  implicit object OpI extends CanExp[Int,Double] {
    def apply(v : Int) = scala.math.exp(v);
  }

  implicit object OpL extends CanExp[Long,Double] {
    def apply(v : Long) = scala.math.exp(v);
  }

  implicit object OpF extends CanExp[Float,Double] {
    def apply(v : Float) = scala.math.exp(v);
  }

  implicit object OpD extends CanExp[Double,Double] {
    def apply(v : Double) = scala.math.exp(v);
  }

  implicit object OpC extends CanExp[Complex,Complex] {
    def apply(v: Complex) = Complex(scala.math.cos(v.imag), scala.math.sin(v.imag)) * scala.math.exp(v.real)
  }

  class OpMapValues[From,A,B,To](implicit op : CanExp[A,B], map : CanMapValues[From,A,B,To]) extends CanExp[From,To] {
    def apply(v : From) = map.map(v, op.apply(_));
  }

  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanExp[A,B])
  : CanExp[From,To] = new OpMapValues[From,A,B,To]()(op, map);

  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);
  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);
  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);
  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);
  implicit object OpArrayC extends OpMapValues[Array[Complex],Complex,Complex,Array[Complex]]()(OpC,CanMapValues.OpArrayCC);

  implicit object OpVectorI extends OpMapValues[Vector[Int],Int,Double,Vector[Double]]()
  implicit object OpVectorL extends OpMapValues[Vector[Long],Long,Double,Vector[Double]]()
  implicit object OpVectorF extends OpMapValues[Vector[Float],Float,Double,Vector[Double]]()
  implicit object OpVectorD extends OpMapValues[Vector[Double],Double,Double,Vector[Double]]()

  implicit object OpMatrixI extends OpMapValues[Matrix[Int],Int,Double,Matrix[Double]]()
  implicit object OpMatrixL extends OpMapValues[Matrix[Long],Long,Double,Matrix[Double]]()
  implicit object OpMatrixF extends OpMapValues[Matrix[Float],Float,Double,Matrix[Double]]()
  implicit object OpMatrixD extends OpMapValues[Matrix[Double],Double,Double,Matrix[Double]]()
}



================================================
FILE: src/main/scala/scalala/generic/math/CanLog.scala
================================================
/*
 * Distributed as part of Scalala, a linear algebra library.
 *
 * Copyright (C) 2008- Daniel Ramage
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA
 */

package scalala;
package generic;
package math;

import collection.CanMapValues;
import scalala.operators.UnaryOp
import tensor.{Matrix, Vector}
;

/**
 * Operator type for log(A).
 *
 * @author dramage
 */
trait OpLog extends operators.OpType;
object OpLog extends OpLog;

/**
 * Constructiond delegate for log(A).
 * 
 * @author dramage
 */
trait CanLog[-A,+RV] extends UnaryOp[A,OpLog,RV] {
  def opType = OpLog;
}

object CanLog {
  implicit object OpI extends CanLog[Int,Double] {
    def apply(v : Int) = scala.math.log(v);
  }

  implicit object OpL extends CanLog[Long,Double] {
    def apply(v : Long) = scala.math.log(v);
  }

  implicit object OpF extends CanLog[Float,Double] {
    def apply(v : Float) = scala.math.log(v);
  }

  implicit object OpD extends CanLog[Double,Double] {
    def apply(v : Double) = scala.math.log(v);
  }
  
  class OpMapValues[From,A,B,To](implicit op : CanLog[A,B], map : CanMapValues[From,A,B,To]) extends CanLog[From,To] {
    def apply(v : From) = map.map(v, op.apply(_));
  }

  implicit def opMapValues[From,A,B,To](implicit map : CanMapValues[From,A,B,To], op : CanLog[A,B])
  : CanLog[From,To] = new OpMapValues[From,A,B,To]()(op, map);

  implicit object OpArrayI extends OpMapValues[Array[Int],Int,Double,Array[Double]]()(OpI,CanMapValues.OpArrayID);
  implicit object OpArrayL extends OpMapValues[Array[Long],Long,Double,Array[Double]]()(OpL,CanMapValues.OpArrayLD);
  implicit object OpArrayF extends OpMapValues[Array[Float],Float,Double,Array[Double]]()(OpF,CanMapValues.OpArrayFD);
  implicit object OpArrayD extends OpMapValues[Array[Double],Double,Double,Array[Double]]()(OpD,CanMapValues.OpArrayDD);

  implicit object OpVectorI extends OpMapValues[Vector[Int],Int,Double,Vector[Double]]()
  implicit object OpVectorL extends OpMapValues[Vector[Long],Long,Double,Vector[Double]]()
  implicit object OpVectorF extends OpMapValues[Vector[Float],Float,Double,Vector[Double]]()
  implicit object OpVectorD extends OpMapValues[Vector[Double],Double,Double,Vector[Double]]()

  implicit object OpMatrixI extends OpMapValues[Matrix[Int],Int,Double,Matrix[Double]]()
  implicit object OpMa
Download .txt
gitextract_e_sqcedj/

├── .gitignore
├── LICENSE
├── README
├── build.sbt
├── project/
│   ├── build.properties
│   └── plugins.sbt
├── sbt
└── src/
    ├── main/
    │   ├── java/
    │   │   └── scalala/
    │   │       └── library/
    │   │           └── random/
    │   │               └── MersenneTwisterFast.java
    │   ├── resources/
    │   │   └── scalala.scala
    │   └── scala/
    │       └── scalala/
    │           ├── ScalalaConsole.scala
    │           ├── collection/
    │           │   └── sparse/
    │           │       └── SparseArray.scala
    │           ├── generic/
    │           │   ├── collection/
    │           │   │   ├── CanAppendColumns.scala
    │           │   │   ├── CanBuildTensorForBinaryOp.scala
    │           │   │   ├── CanBuildTensorFrom.scala
    │           │   │   ├── CanCopy.scala
    │           │   │   ├── CanCreateZerosLike.scala
    │           │   │   ├── CanFilterValues.scala
    │           │   │   ├── CanGetActiveValues.scala
    │           │   │   ├── CanGetDouble.scala
    │           │   │   ├── CanGetValue.scala
    │           │   │   ├── CanJoin.scala
    │           │   │   ├── CanMapKeyValuePairs.scala
    │           │   │   ├── CanMapValues.scala
    │           │   │   ├── CanSliceMatrix.scala
    │           │   │   ├── CanSliceTensor.scala
    │           │   │   ├── CanSliceVector.scala
    │           │   │   ├── CanTranspose.scala
    │           │   │   ├── CanView.scala
    │           │   │   ├── CanViewAsTensor1.scala
    │           │   │   ├── CanViewAsTensor2.scala
    │           │   │   ├── CanViewAsVector.scala
    │           │   │   └── CanZipMapValues.scala
    │           │   └── math/
    │           │       ├── CanAbs.scala
    │           │       ├── CanExp.scala
    │           │       ├── CanLog.scala
    │           │       ├── CanMean.scala
    │           │       ├── CanNorm.scala
    │           │       ├── CanSoftmax.scala
    │           │       ├── CanSqrt.scala
    │           │       └── CanVariance.scala
    │           ├── library/
    │           │   ├── Library.scala
    │           │   ├── LinearAlgebra.scala
    │           │   ├── Numerics.scala
    │           │   ├── Plotting.scala
    │           │   ├── Random.scala
    │           │   ├── Statistics.scala
    │           │   ├── Storage.scala
    │           │   └── plotting/
    │           │       ├── Dataset.scala
    │           │       ├── ExportGraphics.scala
    │           │       ├── Figure.scala
    │           │       ├── Figures.scala
    │           │       ├── HistogramBins.scala
    │           │       ├── PaintScale.scala
    │           │       ├── PaintScaleFactory.scala
    │           │       └── XYPlot.scala
    │           ├── operators/
    │           │   ├── BinaryOp.scala
    │           │   ├── BinaryOpRegistry.scala
    │           │   ├── BinaryUpdateOp.scala
    │           │   ├── CanCast.scala
    │           │   ├── OpType.scala
    │           │   ├── Ops.scala
    │           │   ├── Shape.scala
    │           │   ├── TupleOps.scala
    │           │   ├── UnaryOp.scala
    │           │   ├── ValuesMonadic.scala
    │           │   ├── bundles/
    │           │   │   └── VectorSpace.scala
    │           │   └── codegen/
    │           │       ├── BinaryOpGenerator.scala
    │           │       ├── DynamicCompiler.scala
    │           │       └── GeneratedBinaryOp.scala
    │           ├── scalar/
    │           │   ├── Complex.scala
    │           │   ├── RichScalar.scala
    │           │   ├── Scalar.scala
    │           │   ├── ScalarDecimal.scala
    │           │   └── package.scala
    │           └── tensor/
    │               ├── CRSTensor2.scala
    │               ├── Counter.scala
    │               ├── Counter2.scala
    │               ├── DiagonalMatrix.scala
    │               ├── DomainFunction.scala
    │               ├── LiteralRow.scala
    │               ├── Matrix.scala
    │               ├── MatrixSingularException.scala
    │               ├── MatrixTranspose.scala
    │               ├── SelectAll.scala
    │               ├── Tensor.scala
    │               ├── Tensor1.scala
    │               ├── Tensor1Col.scala
    │               ├── Tensor1Proxy.scala
    │               ├── Tensor1Row.scala
    │               ├── Tensor1Slice.scala
    │               ├── Tensor2.scala
    │               ├── Tensor2Transpose.scala
    │               ├── TensorN.scala
    │               ├── TensorProxy.scala
    │               ├── TensorSlice.scala
    │               ├── TensorView.scala
    │               ├── Vector.scala
    │               ├── VectorCol.scala
    │               ├── VectorProxy.scala
    │               ├── VectorRow.scala
    │               ├── VectorSlice.scala
    │               ├── dense/
    │               │   ├── ArrayArrayMatrix.scala
    │               │   ├── DenseArrayTensor.scala
    │               │   ├── DenseMatrix.scala
    │               │   └── DenseVector.scala
    │               ├── domain/
    │               │   ├── CanBuildDomain2.scala
    │               │   ├── CanGetDomain.scala
    │               │   ├── Domain.scala
    │               │   ├── Domain1.scala
    │               │   ├── Domain2.scala
    │               │   ├── DomainN.scala
    │               │   ├── IndexDomain.scala
    │               │   ├── IterableDomain.scala
    │               │   ├── SetDomain.scala
    │               │   ├── TableDomain.scala
    │               │   └── UnionDomain.scala
    │               ├── generic/
    │               │   ├── TensorBuilder.scala
    │               │   ├── TensorKeysMonadic.scala
    │               │   ├── TensorNonZeroKeysMonadic.scala
    │               │   ├── TensorNonZeroMonadic.scala
    │               │   ├── TensorNonZeroPairsMonadic.scala
    │               │   ├── TensorNonZeroTriplesMonadic.scala
    │               │   ├── TensorNonZeroValuesMonadic.scala
    │               │   ├── TensorPairsMonadic.scala
    │               │   ├── TensorTriplesMonadic.scala
    │               │   └── TensorValuesMonadic.scala
    │               ├── mutable/
    │               │   ├── CRSTensor2.scala
    │               │   ├── Counter.scala
    │               │   ├── Counter2.scala
    │               │   ├── Matrix.scala
    │               │   ├── MatrixTranspose.scala
    │               │   ├── Tensor.scala
    │               │   ├── Tensor1.scala
    │               │   ├── Tensor1Col.scala
    │               │   ├── Tensor1Row.scala
    │               │   ├── Tensor1Slice.scala
    │               │   ├── Tensor2.scala
    │               │   ├── Tensor2Transpose.scala
    │               │   ├── TensorProxy.scala
    │               │   ├── TensorSlice.scala
    │               │   ├── Vector.scala
    │               │   ├── VectorCol.scala
    │               │   ├── VectorRow.scala
    │               │   └── VectorSlice.scala
    │               ├── package.scala
    │               └── sparse/
    │                   ├── SparseArrayTensor.scala
    │                   └── SparseVector.scala
    └── test/
        └── scala/
            └── scalala/
                ├── collection/
                │   └── sparse/
                │       └── SparseArrayTest.scala
                ├── generic/
                │   ├── CanAssignIntoTest.scala
                │   └── collection/
                │       ├── CanGetDoubleTest.scala
                │       ├── CanGetValueTest.scala
                │       └── CanMapValuesTest.scala
                ├── library/
                │   ├── LibraryTest.scala
                │   ├── LinearAlgebraTest.scala
                │   ├── NumericsTest.scala
                │   ├── RandomTest.scala
                │   ├── StatisticsTest.scala
                │   └── StorageTest.scala
                ├── operators/
                │   ├── ArrayTest.scala
                │   ├── SparseArrayTest.scala
                │   ├── TupleTest.scala
                │   └── bundles/
                │       └── VectorSpaceTest.scala
                ├── scalar/
                │   └── ComplexTest.scala
                └── tensor/
                    ├── CRSTensor2Test.scala
                    ├── Counter2Test.scala
                    ├── CounterTest.scala
                    ├── DiagonalMatrixTest.scala
                    ├── Tensor2Test.scala
                    ├── TensorTest.scala
                    ├── dense/
                    │   ├── DenseMatrixTest.scala
                    │   ├── DenseVectorConstructorTest.scala
                    │   └── DenseVectorTest.scala
                    └── sparse/
                        └── SparseVectorTest.scala
Download .txt
SYMBOL INDEX (24 symbols across 1 files)

FILE: src/main/java/scalala/library/random/MersenneTwisterFast.java
  class MersenneTwisterFast (line 152) | public class MersenneTwisterFast implements Serializable, Cloneable
    method clone (line 177) | public Object clone() throws CloneNotSupportedException
    method stateEquals (line 185) | public boolean stateEquals(Object o)
    method readState (line 200) | public void readState(DataInputStream stream) throws IOException
    method writeState (line 214) | public void writeState(DataOutputStream stream) throws IOException
    method MersenneTwisterFast (line 230) | public MersenneTwisterFast()
    method MersenneTwisterFast (line 240) | public MersenneTwisterFast(final long seed)
    method MersenneTwisterFast (line 252) | public MersenneTwisterFast(final int[] array)
    method setSeed (line 264) | synchronized public void setSeed(final long seed)
    method setSeed (line 298) | synchronized public void setSeed(final int[] array)
    method nextInt (line 329) | public final int nextInt()
    method nextShort (line 366) | public final short nextShort()
    method nextChar (line 403) | public final char nextChar()
    method nextBoolean (line 439) | public final boolean nextBoolean()
    method nextBoolean (line 482) | public final boolean nextBoolean(final float probability)
    method nextBoolean (line 526) | public final boolean nextBoolean(final double probability)
    method nextByte (line 596) | public final byte nextByte()
    method nextBytes (line 632) | public final void nextBytes(byte[] bytes)
    method nextLong (line 671) | public final long nextLong()
    method nextLong (line 739) | public final long nextLong(final long n)
    method nextDouble (line 814) | public final double nextDouble()
    method nextGaussian (line 883) | public final double nextGaussian()
    method nextFloat (line 1033) | public final float nextFloat()
    method nextInt (line 1072) | public final int nextInt(final int n)
Condensed preview — 173 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,115K chars).
[
  {
    "path": ".gitignore",
    "chars": 133,
    "preview": "*~\n.idea/\n.idea_modules/\n.manager/\nworkspace.xml\nbin/\ndocs/\ntarget/\nlib_managed/\nsrc_managed/\nproject/boot/\nproject/plug"
  },
  {
    "path": "LICENSE",
    "chars": 26531,
    "preview": "                  GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 19"
  },
  {
    "path": "README",
    "chars": 1783,
    "preview": "Scalala is a high performance numeric linear algebra library for Scala,\nwith rich Matlab-like operators on vectors and m"
  },
  {
    "path": "build.sbt",
    "chars": 3042,
    "preview": "\nname := \"scalala\"\n\nversion := \"1.0.0.RC3-SNAPSHOT\"\n\norganization := \"org.scalala\"\n\nscalaVersion := \"2.9.2\"\n\ncrossScalaV"
  },
  {
    "path": "project/build.properties",
    "chars": 18,
    "preview": "sbt.version=0.11.3"
  },
  {
    "path": "project/plugins.sbt",
    "chars": 242,
    "preview": "\nresolvers += \"Proguard plugin repo\" at \"http://siasia.github.com/maven2\"\n\nlibraryDependencies <+= sbtVersion(v => \"com."
  },
  {
    "path": "sbt",
    "chars": 13334,
    "preview": "#!/usr/bin/env bash\n#\n# A more capable sbt runner, coincidentally also called sbt.\n# Author: Paul Phillips <paulp@typesa"
  },
  {
    "path": "src/main/java/scalala/library/random/MersenneTwisterFast.java",
    "chars": 44768,
    "preview": "package scalala.library.random;\nimport java.io.*;\nimport java.util.*;\n\n/**\n * <h3>MersenneTwister and MersenneTwisterFas"
  },
  {
    "path": "src/main/resources/scalala.scala",
    "chars": 332,
    "preview": "import scalala.scalar._;\nimport scalala.tensor.::;\nimport scalala.tensor.mutable._;\nimport scalala.tensor.dense._;\nimpor"
  },
  {
    "path": "src/main/scala/scalala/ScalalaConsole.scala",
    "chars": 3535,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n * \n * Copyright (C) 2008- Daniel Ramage\n * \n * This lib"
  },
  {
    "path": "src/main/scala/scalala/collection/sparse/SparseArray.scala",
    "chars": 36977,
    "preview": "/*\n Copyright 2009 David Hall, Daniel Ramage\n \n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanAppendColumns.scala",
    "chars": 1192,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanBuildTensorForBinaryOp.scala",
    "chars": 1632,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanBuildTensorFrom.scala",
    "chars": 8946,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanCopy.scala",
    "chars": 2122,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanCreateZerosLike.scala",
    "chars": 2255,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanFilterValues.scala",
    "chars": 3427,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanGetActiveValues.scala",
    "chars": 2219,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanGetDouble.scala",
    "chars": 2687,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanGetValue.scala",
    "chars": 2544,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanJoin.scala",
    "chars": 1594,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanMapKeyValuePairs.scala",
    "chars": 1311,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanMapValues.scala",
    "chars": 4229,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanSliceMatrix.scala",
    "chars": 1416,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanSliceTensor.scala",
    "chars": 1081,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanSliceVector.scala",
    "chars": 1073,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanTranspose.scala",
    "chars": 5002,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanView.scala",
    "chars": 1048,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanViewAsTensor1.scala",
    "chars": 2829,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanViewAsTensor2.scala",
    "chars": 2161,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanViewAsVector.scala",
    "chars": 2771,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/collection/CanZipMapValues.scala",
    "chars": 3243,
    "preview": "package scalala\npackage generic\npackage collection\n\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n "
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanAbs.scala",
    "chars": 2491,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanExp.scala",
    "chars": 3577,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanLog.scala",
    "chars": 3247,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanMean.scala",
    "chars": 3703,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanNorm.scala",
    "chars": 1281,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanSoftmax.scala",
    "chars": 1513,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanSqrt.scala",
    "chars": 2435,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/generic/math/CanVariance.scala",
    "chars": 3013,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/Library.scala",
    "chars": 10056,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/LinearAlgebra.scala",
    "chars": 20956,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/Numerics.scala",
    "chars": 6195,
    "preview": "/*\n Copyright 2009 David Hall, Daniel Ramage\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may "
  },
  {
    "path": "src/main/scala/scalala/library/Plotting.scala",
    "chars": 20207,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/Random.scala",
    "chars": 2812,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/Statistics.scala",
    "chars": 6176,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/Storage.scala",
    "chars": 3609,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/Dataset.scala",
    "chars": 3580,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/ExportGraphics.scala",
    "chars": 4964,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/Figure.scala",
    "chars": 4052,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/Figures.scala",
    "chars": 1748,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/HistogramBins.scala",
    "chars": 2611,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/PaintScale.scala",
    "chars": 16855,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/PaintScaleFactory.scala",
    "chars": 2745,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/library/plotting/XYPlot.scala",
    "chars": 6061,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/BinaryOp.scala",
    "chars": 40683,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/BinaryOpRegistry.scala",
    "chars": 1821,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/BinaryUpdateOp.scala",
    "chars": 14465,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/CanCast.scala",
    "chars": 2201,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/OpType.scala",
    "chars": 4255,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/Ops.scala",
    "chars": 23866,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/Shape.scala",
    "chars": 3119,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/TupleOps.scala",
    "chars": 115629,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/UnaryOp.scala",
    "chars": 3361,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/ValuesMonadic.scala",
    "chars": 629,
    "preview": "package scalala.operators\n\nimport scalala.generic.collection.CanMapValues\n\n/**\n *\n * Represents objects that can have th"
  },
  {
    "path": "src/main/scala/scalala/operators/bundles/VectorSpace.scala",
    "chars": 13780,
    "preview": "package scalala\npackage operators\npackage bundles\n\nimport scalar.Scalar\nimport generic.math.CanNorm\nimport generic.colle"
  },
  {
    "path": "src/main/scala/scalala/operators/codegen/BinaryOpGenerator.scala",
    "chars": 14059,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/operators/codegen/DynamicCompiler.scala",
    "chars": 7923,
    "preview": "/*\n * Copyright 2010 Twitter, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may\n * not "
  },
  {
    "path": "src/main/scala/scalala/operators/codegen/GeneratedBinaryOp.scala",
    "chars": 100368,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/scalar/Complex.scala",
    "chars": 13098,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/scalar/RichScalar.scala",
    "chars": 276,
    "preview": "package scalala.scalar\n\nclass RichScalar(value: Double) {\n  def +(c: Complex): Complex = Complex(value, 0) + c;\n  def -("
  },
  {
    "path": "src/main/scala/scalala/scalar/Scalar.scala",
    "chars": 7650,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/scalar/ScalarDecimal.scala",
    "chars": 1790,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/scalar/package.scala",
    "chars": 1230,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/CRSTensor2.scala",
    "chars": 4381,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Counter.scala",
    "chars": 5081,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Counter2.scala",
    "chars": 5722,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/DiagonalMatrix.scala",
    "chars": 1554,
    "preview": "package scalala\npackage tensor\n\nimport domain.TableDomain\nimport scalar.Scalar\n\n/**\n * A matrix with values only on its "
  },
  {
    "path": "src/main/scala/scalala/tensor/DomainFunction.scala",
    "chars": 1960,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/LiteralRow.scala",
    "chars": 13081,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Matrix.scala",
    "chars": 10750,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/MatrixSingularException.scala",
    "chars": 1072,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/MatrixTranspose.scala",
    "chars": 2011,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/SelectAll.scala",
    "chars": 275,
    "preview": "package scalala.tensor\n\n/**\n * For selecting all elements from a matrix row or column.\n * See :: literal.\n *\n * @author "
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor.scala",
    "chars": 24870,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1.scala",
    "chars": 3729,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Col.scala",
    "chars": 2997,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Proxy.scala",
    "chars": 1614,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Row.scala",
    "chars": 3698,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor1Slice.scala",
    "chars": 1728,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor2.scala",
    "chars": 11090,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Tensor2Transpose.scala",
    "chars": 2341,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorN.scala",
    "chars": 1555,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorProxy.scala",
    "chars": 3950,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorSlice.scala",
    "chars": 2537,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/TensorView.scala",
    "chars": 5731,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/Vector.scala",
    "chars": 4550,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorCol.scala",
    "chars": 3706,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorProxy.scala",
    "chars": 1451,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorRow.scala",
    "chars": 3197,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/VectorSlice.scala",
    "chars": 4029,
    "preview": "\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libr"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/ArrayArrayMatrix.scala",
    "chars": 1584,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/DenseArrayTensor.scala",
    "chars": 2118,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/DenseMatrix.scala",
    "chars": 18316,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/dense/DenseVector.scala",
    "chars": 24959,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/CanBuildDomain2.scala",
    "chars": 1690,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/CanGetDomain.scala",
    "chars": 3333,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/Domain.scala",
    "chars": 1753,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/Domain1.scala",
    "chars": 1927,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/Domain2.scala",
    "chars": 3386,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/DomainN.scala",
    "chars": 2862,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/IndexDomain.scala",
    "chars": 1955,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/IterableDomain.scala",
    "chars": 2537,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/SetDomain.scala",
    "chars": 1485,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/TableDomain.scala",
    "chars": 2046,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/domain/UnionDomain.scala",
    "chars": 1677,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorBuilder.scala",
    "chars": 1155,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorKeysMonadic.scala",
    "chars": 2997,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroKeysMonadic.scala",
    "chars": 2545,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroMonadic.scala",
    "chars": 1974,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroPairsMonadic.scala",
    "chars": 3366,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroTriplesMonadic.scala",
    "chars": 3454,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorNonZeroValuesMonadic.scala",
    "chars": 3423,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorPairsMonadic.scala",
    "chars": 3620,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorTriplesMonadic.scala",
    "chars": 3385,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/generic/TensorValuesMonadic.scala",
    "chars": 3342,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/CRSTensor2.scala",
    "chars": 3256,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Counter.scala",
    "chars": 3529,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Counter2.scala",
    "chars": 4676,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Matrix.scala",
    "chars": 4600,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/MatrixTranspose.scala",
    "chars": 2018,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor.scala",
    "chars": 7042,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1.scala",
    "chars": 1613,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1Col.scala",
    "chars": 2318,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1Row.scala",
    "chars": 2607,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor1Slice.scala",
    "chars": 2060,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor2.scala",
    "chars": 6609,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Tensor2Transpose.scala",
    "chars": 2409,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/TensorProxy.scala",
    "chars": 3258,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/TensorSlice.scala",
    "chars": 2207,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/Vector.scala",
    "chars": 5077,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/VectorCol.scala",
    "chars": 1899,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/VectorRow.scala",
    "chars": 1898,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/mutable/VectorSlice.scala",
    "chars": 3772,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/package.scala",
    "chars": 889,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/sparse/SparseArrayTensor.scala",
    "chars": 2101,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/main/scala/scalala/tensor/sparse/SparseVector.scala",
    "chars": 11371,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/collection/sparse/SparseArrayTest.scala",
    "chars": 2083,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/generic/CanAssignIntoTest.scala",
    "chars": 1766,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/generic/collection/CanGetDoubleTest.scala",
    "chars": 1360,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/generic/collection/CanGetValueTest.scala",
    "chars": 1366,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/generic/collection/CanMapValuesTest.scala",
    "chars": 1455,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/library/LibraryTest.scala",
    "chars": 5562,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This library is fre"
  },
  {
    "path": "src/test/scala/scalala/library/LinearAlgebraTest.scala",
    "chars": 5797,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/library/NumericsTest.scala",
    "chars": 2974,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/library/RandomTest.scala",
    "chars": 1690,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/library/StatisticsTest.scala",
    "chars": 1768,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/library/StorageTest.scala",
    "chars": 2415,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/operators/ArrayTest.scala",
    "chars": 2209,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/operators/SparseArrayTest.scala",
    "chars": 2291,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/operators/TupleTest.scala",
    "chars": 2278,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/operators/bundles/VectorSpaceTest.scala",
    "chars": 1607,
    "preview": "package scalala\npackage operators\npackage bundles\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * "
  },
  {
    "path": "src/test/scala/scalala/scalar/ComplexTest.scala",
    "chars": 3001,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/CRSTensor2Test.scala",
    "chars": 3294,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/Counter2Test.scala",
    "chars": 4069,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/CounterTest.scala",
    "chars": 2605,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/DiagonalMatrixTest.scala",
    "chars": 1404,
    "preview": "package scalala.tensor\n\n/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel"
  },
  {
    "path": "src/test/scala/scalala/tensor/Tensor2Test.scala",
    "chars": 2550,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/TensorTest.scala",
    "chars": 3013,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/dense/DenseMatrixTest.scala",
    "chars": 7232,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/dense/DenseVectorConstructorTest.scala",
    "chars": 6629,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/dense/DenseVectorTest.scala",
    "chars": 5133,
    "preview": "/*\n * Distributed as part of Scalala, a linear algebra library.\n *\n * Copyright (C) 2008- Daniel Ramage\n *\n * This libra"
  },
  {
    "path": "src/test/scala/scalala/tensor/sparse/SparseVectorTest.scala",
    "chars": 1406,
    "preview": "package scalala.tensor.sparse\n\nimport org.scalatest._\nimport org.scalatest.matchers.ShouldMatchers\nimport org.scalatest."
  }
]

About this extraction

This page contains the full source code of the scalala/Scalala GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 173 files (1.0 MB), approximately 333.7k tokens, and a symbol index with 24 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!