Skip to content

Commit

Permalink
Magicl NG (#63)
Browse files Browse the repository at this point in the history
* Add initial version of magicl high-level rewrite

* Add *derive-function-types* to asdf project

* Add random, fix multiplication, add lapack, make things work

* Fix idenetity typo

* Fix empty and deye documentation and fix assert-square-matrix printing whole matrix

* Remove FASL in high-level dir (Why was that there?)

* Fix indentation in matrix.lisp and clean up trace

* Add macro to generate blas mult boilerplate

* Remove old version of matrix/double-float

* Add lapack macros to make mult work

* Fix from-*-major-index and add tests for util file

* Move lapack method definitions into macros for ease of use

* Add square restriction to qr/ql/rq/lq

* Remove magicl from :use on packages to avoid shadowing errors

* Add support for calling PPRINT-MATRIX within FORMAT

* Add distribution as function to RAND and add tests

* Add lapack inverse to high level and finish updating examples to new interface

* Remove debug message from lapack-inv

* Update TEST-RANDOM-UNITARY and TEST-LOGM to new interface

* Fix TEST-KRON

* Gave it some throught. It should work.

* Add p-norm to vector type

* Add slice to ABSTRACT-TENSOR

- Slice implemented for abstract-tensor
- Docstrings cleaned up
- TODOs TODONE

* Remove TODO regarding if it makes sense. It makes sense.

* Fix tests not calling all the tests

* Fix constant redefinition in magicl-tests caused by incorrect test predicate

* Extract function for type inferring in tensor constructors

* Clean up TODOs in high-level

* Reduce oddity in abstract-tensor-tests and include dim=1 case

* Fix TEST-TENSOR-SHAPE and TEST-TENSOR-RANK with more advanced loops

* Remove unneeded multiplication of shape in FROM-DIAG constructor

* Update high-level docstrings to be more uniform and descriptive and add order parameters to map and into

* Implement VALID-INDEX-P properly and use in high-level

* Fix teh typo and bad indentation in high-level-tests

* Fix indentation in INFER-TENSOR-TYPE

* Fix VALID-INDEX-P to allow for not specifying shape

* Make map and into functions more readable

* Change high-level constructors to functions from generic functions

* Make DEFVECTOR/DEFMATRIX macros more expandable

* Add HERMITIAN-EIG to new high-level interface

* Fix appleby's nitpicks

* Add policy-cond for performance when speed > safety and directly construct classes

* Switch from CLOS to structs for tensor objects

This gives a significant performance improvement due to avoiding generics
at the cost of some flexibility and my sanity.

* Remove freeze on tensor struct causing type error

* Fix pretty printing for matrix and tensor types and remove old methods

* Remove accidentally committed log files

* Add (SETF SHAPE) and optimize matrix TREF

* Remove warnings from unused arguments and load order

* Add basic documentation for high-level interface

* Fix bug in transpose on matrix with dimension of 1

* Add integer printing to matrix and vector pretty printers

* Change from dynamic to static symbols in INFER-TENSOR-TYPE and move to appropriate file

* Add CAST, a replacement for CHANGE-CLASS on tensors

* Clean up util and comments

* Add subtypes and straggling symbols to package

* Add reduced svd interface and tests (#65)

* Add CSD-2X2-BASIC (#67)

* Use use-expectations in the expected way

* Change ABSTRACT-TENSOR to not allow for construction or copying

* Move magicl high-level into module in ASDF

* Clean up documentation for ABSTRACT-TENSOR

* Replace POLICY-IF with WITH-EXPECTATIONS in constructors

* Fix mistake in abstract-tensor docstring

* Use COPY-SEQ for copying tensor storage and add copiers to vector

* Remove funky comma in ASSERT-SQUARE-SHAPE

* Move lapack bindings to lapack-bindings.lisp and switch to functions to generate lapack code

* Update docstrings for DEFTENSOR, DEFMATRIX, DEFVECTOR, and DEFCOMPATIBLE

* Fix other library equivalents table errors

Co-Authored-By: Juan M. Bello-Rivas <[email protected]>

* Change def- to generate- in lapack-templates to reflect change from macro to func

* Add numpy rq to high-level doc

* Change terminology regarding indexing and number of dimensions of tensors

ORDER is now LAYOUT
RANK is now ORDER

* Remove LAYOUT arg from INTO! and FOREACH in abstract tensor interface

These fields do not make sense to have on a method which is calling a function independent of the ordering of the elements

* Add ZEROS and ONES constructors for convenience

* Remove square requirement from DEYE constructor

* Remove ORDER 2 requirement from DEYE

* Rename DEYE to EYE

* Add TRIL and TRIU synonyms and change DAGGER(!) to synonyms

* Add TRIL/TRIU to package

* Add issue number to ZUNCSD shim

* Replace = with := in LOOPs

* Allow for FIXNUM in EYE shape and remove SHAPE requirement from FROM-DIAG

* Update tests to refelect change in FROM-DIAG interface

* Add BINARY-OPERATOR method and add '.' prefix to element-wise operators

* Update documentation for elementwise operators

* Remove unwanted argument on FROM-DIAG

* Fix typo, represening how bad I am at speling

* Fix RAND docstring to be more documenting

* Allow for multiple tensors in every, any, notevery, notany

* Fix bug in hermitian-eig caused by copying/resetting layout slot on return and export method

* Export slice and mult from high-level

* Fix expm returning incorrect layout for result

* Bump version to 0.7.0

* Symbol case invariance. Drop unused declarations (#74)

* Add optimizations for MATRIX class

Add matrix-{row,column}-major-index
Add specialized INTO! for MATRIX class
Add make-storage for matrix class

* Update documentation to be more correct

Apply suggestions from code review

Co-Authored-By: appleby <[email protected]>

* Change INVERSE -> INV

* Change POLICY-IF to POLICY-COND

herminitan-matrix-p has a strict epsilon added to avoid test failures

* Fix LAYOUT->ORDER in high-level docs

* Fix indentation in high-level docs

* Fix deye->eye in high-level docs

* Add check for valid index to tref and setf tref in vector and tensor classes

* Change default tensor type to var to allow for rebinding

* Remove unneeded variable in hermitian-eig

* Force square shape for upper and lower triangular of matrix

* Update element-wise exponentiation in high-level docs to be consistent

* Update examples.lisp

Co-Authored-By: Erik Davis <[email protected]>

* Remove layout from ARANGE constructor

layout is not needed because it returns a vector

* Fix tensor equality errors and add corresponding tests

* Add equality for float vectors and fix error in high-level tests

* Overhaul p-norm for vectors and add tests

* Update documentation for numpy hermitian transpose

* Fix p-norm for infinite norm of negative single element vectors

* Change float comparison thresholds to variables

* Change *-MATRIX-P to functions

* Fix incorrect assertion in p-norm of vector

* Apply suggestions from code review

Co-Authored-By: Erik Davis <[email protected]>

* Remove ORTHONORMALIZE methods for matrices (just use QR)

* Add check for singular matrices in INV folllowing call to LU

* Remove old note about LU requried for INV.

INV now calls the LU LAPACK routine directly and does not require LU to be defined.

* Add P-NORM-TYPE and modify vector norm to use type and to disallow negative infinity

Co-authored-by: Juan M. Bello-Rivas <[email protected]>
Co-authored-by: appleby <[email protected]>
Co-authored-by: Erik Davis <[email protected]>
  • Loading branch information
4 people authored Feb 26, 2020
1 parent 122969c commit a37039a
Show file tree
Hide file tree
Showing 37 changed files with 3,275 additions and 1,388 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ You can run the MAGICL tests from your Lisp REPL with:
(asdf:test-system :magicl)
```

## High-level Interface

See [high-level doc](doc/high-level.md).

## Showing Available Functions

Some distributions of a library don't actually provide all of the functions of the reference BLAS and LAPACK. One can look at a summary of available and unavailable functions with the function `magicl:print-availability-report`. By default, it will show all functions and their availability. There are three arguments to fine-tune this behavior:
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"0.6.5"
"0.7.0"
83 changes: 83 additions & 0 deletions doc/high-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# High Level Bindings

The purpose of the high-level magicl bindings is to allow for MATLAB-like multidimensional arrays in lisp.

## Constructors

The construction of tensors can be done with any of the given constructors. The constructors take a shape and arguments for method of construction.

Tensors are specialized on both the shape and the element type. The class of a tensor will be of the form `$CLASS/$TYPE` (e.g. `MATRIX/DOUBLE-FLOAT`).

| Number of dimensions | Tensor Class |
|----------------------|-----------------|
| 1 | `VECTOR` |
| 2 | `MATRIX` |
| * | `TENSOR` |

| Element Type | Class Suffix |
|--------------------------|------------------------|
| `SINGLE-FLOAT` | `SINGLE-FLOAT` |
| `DOUBLE-FLOAT` | `DOUBLE-FLOAT` |
| `(COMPLEX SINGLE-FLOAT)` | `COMPLEX-SINGLE-FLOAT` |
| `(COMPLEX DOUBLE-FLOAT)` | `COMPLEX-DOUBLE-FLOAT` |
| `(SIGNED-BYTE 32)` | `INT32` |

The type of the elements of the tensor can be specified with the `:type` keyword, or the constructor will attempt to find an appropriate type from the given arguments. The default element type for a tensor is `DOUBLE-FLOAT`.

The layout of the tensor (column-major or row-major) can be specified with the `:layout` keyword. This affects the underlying storage of the tensor and will affect how it carries out operations with LAPACK.


## Other Library Equivalents

This table was adapted largely from the [NumPy Equivalents Table](https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html#linear-algebra-equivalents).

### Basic Accessors

| MAGICL | MATLAB | NumPy | Description |
|----------------|------------|-------------------------|---------------------------------------------------------------|
| `(order a)` | `ndims(a)` | `ndim(a)` or `a.ndim` | Get the number of dimensions of the array. |
| `(size a)` | `numel(a)` | `size(a)` or `a.size` | Get the number of elements of the array. |
| `(shape a)` | `size(a)` | `shape(a)` or `a.shape` | Get the shape of the array. |
| `(tref a 1 4)` | `a(2,5)` | `a[1, 4]` | Get the element in the second row, fifth column of the array. |

### Constructors

| MAGICL | MATLAB | NumPy | Description |
|-------------------------------------------------|--------------------|-----------------------------------|--------------------------------------------------------------------------------------|
| `(from-list '(1d0 2d0 3d0 4d0 5d0 6d0) '(2 3))` | `[ 1 2 3; 4 5 6 ]` | `array([[1.,2.,3.], [4.,5.,6.]])` | Create a 2x3 matrix from given elements. |
| `(zeros '(2 3 4))` or `(const 0d0 '(2 3 4))` | `zeros(2,3,4)` | `zeros((2,3,4))` | Create a 2x3x4 dimensional array of zeroes of double-float element type. |
| `(ones '(3 4)` or `(const 1d0 '(3 4))` | `ones(3,4)` | `ones((3,4))` | Create a 3x4 dimensional array of ones of double-float element type. |
| `(eye 1d0 '(3 3))` | `eye(3)` | `eye(3)` | Create a 3x3 identity array of double-float element type. |
| `(from-diag a)` | `diag(a)` | `diag(a)` | Create a square matrix from the diagonal entries in `a` with zeroes everywhere else. |
| `(rand '(3 4))` | `rand(3,4)` | `random.rand(3,4)` | Create a random 3x4 array. |

### Basic Operations

| MAGICL | MATLAB | NumPy | Description |
|------------|----------|------------------|-----------------------------|
| `(@ a b)` | `a * b` | `a @ b` | Matrix multiplication |
| `(.+ a b)` | `a + b` | `a + b` | Element-wise add |
| `(.- a b)` | `a - b` | `a - b` | Element-wise subtract |
| `(.* a b)` | `a .* b` | `a * b` | Element-wise multiply |
| `(./ a b)` | `a./b` | `a/b` | Element-wise divide |
| `(.^ a b)` | `a.^b` | `np.power(a,b)` | Element-wise exponentiation |

### Linear Algebra

| MAGICL | MATLAB | NumPy | Description |
|---------------------------------------------------------|-------------------|----------------------------------------------------------------|--------------------------------------------|
| `(det a)` | `det(a)` | `linalg.det(a)` | Determinant of matrix |
| `(trace a)` | `trace(a)` | `trace(a)` | Trace (sum of diagonal elements) of matrix |
| `(upper-triangular a)` | `triu(a)` | `triu(a)` | Upper triangular part of matrix |
| `(lower-triangular a)` | `tril(a)` | `tril(a)` | Lower triangular part of matrix |
| `(transpose a)` | `a.'` | `a.transpose()` or `a.T` | Transpose of matrix |
| `(conjugate-transpose a)` or `(dagger a)` | `a'` | `a.conj().transpose()` or `a.H` | Conjugate transpose of matrix |
| `(inv a)` | `inv(a)` | `linalg.inv(a)` | Inverse of matrix |
| `(svd a)` (Returns `(VALUES U SIGMA Vt)`) | `[U,S,V]=svd(a)` | `U, S, Vh = linalg.svd(a), V = Vh.T` | Singular value decomposition of matrix |
| `(eig a)` (Returns `(VALUES EIGENVALUES EIGENVECTORS)`) | `[V,D]=eig(a)` | `D,V = linalg.eig(a)` | Eigenvalues and eigenvectors of matrix |
| `(qr a)` (Returns `(VALUES Q R)`) | `[Q,R,P]=qr(a,0)` | `Q,R = scipy.linalg.qr(a)` | QR factorization of matrix |
| `(ql a)` (Returns `(VALUES Q L)`) | | | QL factorization of matrix |
| `(rq a)` (Returns `(VALUES R Q)`) | | `R,Q = scipy.linalg.rq(a)` | RQ factorization of matrix |
| `(lq a)` (Returns `(VALUES L Q)`) | | | LQ factorization of matrix |
| `(lu a)` (Returns `(VALUES LU IPIV)`) | `[L,U,P]=lu(a)` | `L,U = scipy.linalg.lu(a)` or `LU,P=scipy.linalg.lu_factor(a)` | LU decomposition of matrix |
| `(csd a)` (Returns `(VALUES U SIGMA VT)`) | | | Cosine-sine decomposition of matrix |
Loading

0 comments on commit a37039a

Please sign in to comment.