Coverage report: /home/ellis/comp/core/lib/obj/tensor/proto.lisp
Kind | Covered | All | % |
expression | 3 | 43 | 7.0 |
branch | 0 | 0 | nil |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; proto.lisp --- Tensor Protocols
7
;; This file contains the 'high-level' tensor protocol. See meta.lisp for the
11
(in-package :obj/tensor)
14
(defparameter *default-sparse-store-increment* 100
15
"Determines the increment by which the store of a compressed sparse matrix is
16
increased, when it runs out of store.")
18
(defparameter *default-sparsity* 1/1000
19
"Determines the default sparsity for a newly created sparse matrix, when the
20
number of non-zero is not specified.")
22
(defparameter *max-sparse-size* 10000
23
"Upper bounds the store size for a newly created sparse matrix, when the number
24
of non-zero is not specified.")
26
;;Default ordering of strides
28
(defparameter *default-stride-ordering* :col-major
29
"Determines whether strides are row or column major by default.
31
(let ((*default-stride-ordering* :col-major))
32
(make-real-tensor 10 10))
33
;; returns a 10x10 matrix in Column major order."))
35
(defparameter *default-tensor-type* 'real-tensor)
37
(defparameter *tensor-safety-p* t
38
"If non-nil, then check for invalid values in the field of the class in the
39
:after specialized method (if defined), else do nothing. One ought to be very
40
carful when doing, much of Matlisp's code is written on the assumption that
41
the fields of a tensor don't take invalid values; failing which case, may lead
42
to memory error. Use at your own risk.")
44
(defparameter *print-tensor-max-len* 10
45
"Maximum number of elements in any particular argument to print.
46
Set this to T to print all the elements.")
48
(defparameter *print-tensor-max-args* 5
49
"Maximum number of arguments of the tensor to print.
50
Set this to T to print all the arguments.")
52
(defparameter *print-tensor-indent* 0
53
"Determines how many spaces will be printed before each row
54
of a matrix (default 0)")
57
(define-condition tensor-invalid-dimension-value (error)
58
((argument :initarg :argument)
59
(dimension :initarg :dimension))
62
(with-slots (argument dimension) c
63
(format s "Invalid dimension arg: ~A~%dimension: ~A" argument dimension)))))
66
(deftype index-type () 'fixnum)
68
(deftype index-store-vector (&optional (size '*)) `(simple-array index-type (,size)))
71
(defgeneric print-element (tensor
73
(:documentation "This generic function is specialized to TENSOR to print ELEMENT to STREAM.
74
Called by PRINT-TENSOR/MATRIX to format a tensor into the STREAM."))
76
(defgeneric size (obj)
77
(:method ((obj sequence))
79
(:method ((arr array))
80
(reduce #'* (array-dimensions arr))))
82
(defgeneric store-size (tensor)
83
(:documentation "Returns the number of elements the store of the tensor can hold (which is not
84
necessarily equal to its vector length)."))
86
(defgeneric store-ref (tensor idx)
87
(:documentation "Generic serial read access to the store."))
89
(defgeneric (setf store-ref) (value tensor idx))
91
(defgeneric subtensor (tensor subscripts)
92
(:documentation "Creates a new tensor data structure, sharing store with TENSOR but with
93
different strides and dimensions, as defined in the subscript-list SUBSCRIPTS.
96
(defvar X (make-real-tensor 10 10 10))
100
(subtensor X '((nil nil . nil) (0 1 . nil) (0 1 . nil)))
102
(subtensor X '((nil nil . nil) (2 5 . nil)))
103
;; Get (: : 0:2:10) (0:10:2 = [i : 0 <= i < 10, i % 2 = 0])
104
(subtensor X '((nil nil . nil) (nil nil . nil) (0 10 . 2)))
106
Sadly in our parentheses filled world, this function has to be necessarily
107
verbose (unlike MATLAB, Python). However, this function has been designed with
108
the express purpose of using it with a Lisp reader macro. The slicing
109
semantics is essentially the same as MATLAB except for the zero-based
112
(defgeneric suptensor (tensor ord &optional start))
114
(defgeneric reshape (tensor dims)
115
(:documentation "Reshape TENSOR to DIMS. This function expects all the strides to be of the
116
same sign when TENSOR is subtype of STANDARD-TENSOR."))
118
(defgeneric ref (tensor &rest subscripts)
119
(:documentation "Return the element from TENSOR corresponding to SUBSCRIPTS"))
121
(defgeneric (setf ref) (value tensor &rest subscripts))
124
(:method ((x complex))
130
;; base-tensor, dense/sparse
131
;; standard-tensor (lisp)
132
;; static-tensor, c-tensor
133
;; blas-tensor, lapack-tensor