Coverage report: /home/ellis/comp/core/lib/obj/tensor/util.lisp
Kind | Covered | All | % |
expression | 0 | 82 | 0.0 |
branch | 0 | 2 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; util.lisp --- Tensor Utils
6
(in-package :obj/tensor)
8
(defmacro with-no-init-checks (&body body)
9
`(let ((*tensor-safety-p* nil))
12
(defun subfieldp (a b)
13
(subtypep (field-type a) (field-type b)))
15
(defun t.zeros (ty dims &optional (initial-element 0))
16
(let* ((adims (make-index-store dims)))
17
(declare (index-store-vector adims))
18
(multiple-value-bind (astrs sizs) (make-stride adims)
19
(declare (type index-store-vector astrs))
24
:store (t.store-allocator ty sizs initial-element)))))
26
;; (deft t.zeros (class coordinate-sparse-tensor) (dims &optional nz)
27
;; (with-gensyms (astrs adims sizs)
28
;; `(let* ((,adims (make-index-store ,dims)))
29
;; (declare (type index-store-vector ,adims))
30
;; (multiple-value-bind (,astrs ,sizs) (make-stride-cmj ,adims)
31
;; (declare (type index-store-vector ,astrs))
32
;; (make-instance ',class
35
;; :store (t.store-allocator ,class ,sizs ,nz))))))
37
;; (deft t.zeros (class compressed-sparse-matrix) (dims &optional nz)
38
;; (with-gensyms (dsym)
39
;; `(let ((,dsym ,dims))
40
;; (destructuring-bind (vr vd) (t.store-allocator ,class ,dsym ,nz)
41
;; (make-instance ',class
42
;; :dimensions (make-index-store ,dims)
43
;; :neighbour-start (allocate-index-store (1+ (second ,dsym)))
47
(defgeneric %zeros (dims dtype &optional initial-element)
48
(:documentation "internal dispatch for ZEROS.")
49
(:method ((dims cons) (dtype t) &optional initial-element)
50
;; (assert (member dtype *tensor-type-leaves*) nil 'tensor-abstract-class :tensor-class dtype)
52
(t.zeros dtype dims initial-element)
53
(t.zeros dtype dims))))
55
(definline zeros (dims &optional (type *default-tensor-type*) (initial-element 0))
56
"Create a tensor with dimensions @arg{dims} of class @arg{dtype}.
57
The optional argument @arg{initial-element} is used in two completely
60
If TYPE is a dense tensor, then INITIAL-ELEMENT, is used to initialize all the
61
elements. If TYPE is however, a sparse tensor, it is used for computing the
62
number of nonzeros slots in the store.
70
(zeros 3 'complex-tensor 2)
75
(zeros '(10000 10000) 'real-compressed-sparse-matrix 10000)
76
#<REAL-COMPRESSED-SPARSE-MATRIX #(10000 10000), store-size: 10000>"
80
(%zeros dims type initial-element))
82
(%zeros (vector-to-list dims) type initial-element))
84
(%zeros (list dims) type initial-element)))))
86
(declaim (ftype (function ((or cons vector fixnum) &optional t t) base-tensor) zeros))
88
(defmacro with-rowm (&rest body)
89
`(let ((*default-stride-ordering* :row-major))
92
(defmacro with-colm (&rest body)
93
`(let ((*default-stride-ordering* :col-major))
97
(definline nrows (matrix)
98
(aref (the index-store-vector (dimensions matrix)) 0))
100
(definline ncols (matrix)
101
(aref (the index-store-vector (dimensions matrix)) 1))
103
(definline row-stride (matrix)
104
(aref (the index-store-vector (strides matrix)) 0))
106
(definline col-stride (matrix)
107
(aref (the index-store-vector (strides matrix)) 1))
109
(definline tensor-square-matrixp (matrix)
110
(and (tensor-matrixp matrix) (tensor-squarep matrix)))