;;
;; test-pmfg-extract.scm - Extract full PMFG output values
;;
(use-modules (opencog) (opencog exec))
(use-modules (opencog sensory) (opencog opencl))
(use-modules (ice-9 format))
(display "\n=== PMFG Output Extraction Test ===\n\n")
;; Build simple 5x5 MI matrix
(define mi-vals
(list 0.0 5.0 1.0 0.5 0.1
5.0 0.0 4.0 0.8 0.2
1.0 4.0 0.0 3.0 0.3
0.5 0.8 3.0 0.0 2.0
0.1 0.2 0.3 2.0 0.0))
;; GPU setup
(define gpu (OpenclNode "opencl://:/storage/projects/code/hypercore-kb/opencog-kb/language-learning/mvp/pmfg-kernel.cl"))
;; Run PMFG
(cog-execute!
(SetValue gpu (Predicate "*-write-*")
(Section (Item "pmfg_single")
(ConnectorSeq
(apply Number mi-vals)
(Number 0 1 2 3 4)
(Number 5)
(Number 5)
(Number 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
(Number 0)))))
(define result (cog-execute! (ValueOf gpu (Predicate "*-read-*"))))
;; Extract the args
(define args (cog-value-ref result 1))
(display "Full args:\n")
;; args is a LinkValue - iterate through it
(do ((i 0 (+ i 1))) ((= i 7))
(let ((v (cog-value-ref args i)))
(format #t " [~a] type=~a value=~a~%" i (cog-type v) v)))
;; Try to get full values from OpenclFloatValue
(display "\nAttempting to read OpenclFloatValue contents:\n")
(define edges-val (cog-value-ref args 4))
(define nedges-val (cog-value-ref args 5))
(format #t "edges-val type: ~a~%" (cog-type edges-val))
(format #t "nedges-val type: ~a~%~%" (cog-type nedges-val))
;; cog-value->list should work on FloatValues
(catch #t
(lambda ()
(format #t "edges (cog-value->list): ~a~%" (cog-value->list edges-val)))
(lambda (key . args)
(format #t "Error getting edges: ~a ~a~%" key args)))
(catch #t
(lambda ()
(format #t "n_edges (cog-value->list): ~a~%" (cog-value->list nedges-val)))
(lambda (key . args)
(format #t "Error getting n_edges: ~a ~a~%" key args)))
;; Try cog-value-ref on the FloatValue elements
(display "\nTrying individual element access:\n")
(catch #t
(lambda ()
(do ((i 0 (+ i 1))) ((= i 18))
(format #t " edges[~a] = ~a~%" i (cog-value-ref edges-val i))))
(lambda (key . args)
(format #t "Element access error: ~a~%" key)))