Coverage report: /development/source/library/org/datagraph/spocq-shard/src/algebra/matrix-operators/slice.lisp
| Kind | Covered | All | % |
| expression | 0 | 60 | 0.0 |
| branch | 0 | 4 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: org.datagraph.spocq.implementation; -*-
3
(in-package :org.datagraph.spocq.implementation)
5
(:documentation "sparql slice operation for matrix fields as immediates or as streams")
7
;;; (load (compile-file "/development/source/library/org/datagraph/spocq/src/algebra/matrix-operators/slice.lisp"))
10
(defmethod spocq.e:slice ((source-field matrix-field) &rest args &key end start)
11
"The SLICE reduction method applys the matrix operator the matrix arguments and returns the result"
12
(declare (dynamic-extent args))
14
(let* ((base-dimensions (matrix-field-dimensions source-field))
15
(length (- (or end (field-length source-field)) (or start 0)))
16
(%data (rdfcache:make-matrix length (field-width source-field)))
17
(result-field (clone-matrix-field source-field :data %data))
18
(operator (matrix-slice-operator base-dimensions base-dimensions)))
19
(apply operator result-field source-field
24
(defmethod process-slice ((result-field matrix-page-channel)
25
(source-field matrix-page-channel)
27
&rest arguments &key start end)
28
"The SLICE streaming operator applies the matrix operator to the streams and returns the counts"
29
(declare (ignore start end)
30
(dynamic-extent arguments))
31
(let ((operator (matrix-slice-operator (channel-dimensions result-field) base-dimensions)))
32
(apply operator result-field source-field
34
(values (channel-solution-count source-field)
35
(channel-solution-count result-field)))
38
(defun matrix-slice-operator (result-dimensions source-dimensions)
39
;; compute the mapping and suppress non-distinguished variables
40
(let ((projection (loop for source-dimension in source-dimensions
41
collect (when (distinguished-variable-p source-dimension) (position source-dimension result-dimensions)))))
42
(ensure-matrix-operator 'slice :projection projection :result-column-count (length result-dimensions))))
45
(defmethod compute-matrix-operator-lambda ((operator (eql 'slice)) &key projection result-column-count)
46
(let* ((source-column-count (length projection)))
47
`(lambda (result-field source-field &key (start 0) end)
48
,(format nil "slice operator for projection: ~s." projection)
49
(declare (type matrix-field result-field source-field)
50
(optimize ,@*field-optimization*)
53
(unless (= (field-width result-field) ,result-column-count) ()
54
(matrix-dimension-error :matrix result-field :expected-dimensions '(* ,result-column-count)))
55
(unless (= (field-width source-field) ,source-column-count) ()
56
(matrix-dimension-error :matrix source-field :expected-dimensions '(* ,source-column-count)))
58
(let ((%source-data (cffi::null-pointer))
59
(%result-data (cffi::null-pointer))
64
(declare (foreign-type (foreign-array ,+matrix-element-type+ (* ,source-column-count)) %source-data)
65
(foreign-type (foreign-array ,+matrix-element-type+ (* ,result-column-count)) %result-data)
66
(type sb-sys:system-area-pointer %source-data %result-data)
67
(type fixnum source-row result-row result-count)
69
;; first, position in the page with the start
70
(loop with page-length = (field-page-length source-field)
71
until (or (>= (incf result-count page-length) start)
72
(null (setf start-page (get-field-page source-field)))))
74
;; then position in page
75
(setf (field-current-read-row source-field)
76
(-1 (- (field-page-length start-page) (- result-count start))))
77
(trace-matrix "~&slice.started ~@{~a ~}" :start start)
78
(setf result-count start)
79
;; and project solutions
80
(loop until (and end (>= result-count (the fixnum end)))
81
until (cffi:null-pointer-p (setf (values %source-data source-row) (next-field-row source-field)))
82
do (progn (setf (values %result-data result-row) (new-field-row result-field))
84
(trace-matrix "~&slice.next-result ~@{~a ~}" :source source-row :result result-row :result-count result-count)
85
(project-foreign-solution (%result-data result-row) (%source-data source-row) ',projection))))
86
(complete-field result-field)
90
;;; (spocq-compile (compute-matrix-operator-lambda 'slice :projection '(1 nil 3 2) :slice t))