Skip to content

Commit

Permalink
Now initializing matrix cells with empty sets (vs. nils)
Browse files Browse the repository at this point in the history
If I initialize env matrix cells by nil, and then conj data
onto the nil, the result is a PersistentList.  When this is
in the first column of the matrix, you can't use mx/pm to
display the matrix, because core.matrix's internal get-shape
function tries to recurse into the first column in order to
find out the dimensionality of the matrix.  It uses count
to do this.  count doesn't work on sets, so core.matrix isn't
confused.  See the issue I submitted:
mikera/core.matrix#361
  • Loading branch information
mars0i committed Apr 28, 2023
1 parent 97b25e0 commit c5c2284
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/clj/forage/env_indexed.clj
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@
;; signature from the version in env_mason.clj.
;;
;; By default new-matrix will initialize with zero doubles, I don't want that
;; because it could be confusing. Instead initialize with nils, which can
;; be conj'ed onto later. Don't use [] for this purpose: It can confuse
;; core.matrix because it thinks the inner vectors are part of the matrix structure.
;; because it could be confusing. Instead initialize with empty sets,
;; which can be conj'ed onto later. Don't use nil or [] for this purpose: It can
;; confuse core.matrix/pm when there is added data in the first column of the
;; matrix.
(defn make-env
"Returns a new environment as a map containing a value of :size which is
dimension of the external representation of a size X size field, a value
Expand All @@ -116,7 +117,7 @@
locations (mx/new-matrix :ndarray size* size*)] ;; Use ndarray internally so mset! works
(doseq [row (range size*)
col (range size*)]
(mx/mset! locations row col nil)) ; this default is assumed by other functions here.
(mx/mset! locations row col #{})) ; this default is assumed by other functions here.
{:size size, :scale scale, :toroidal? toroidal?, :locations locations}))

(defn scale-coord
Expand Down

0 comments on commit c5c2284

Please sign in to comment.