From 156e7c4be36810e8c5926220e48ab3d5793bffe3 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Thu, 27 Jun 2019 10:30:14 +0100 Subject: [PATCH 1/4] Documenting `extract`. --- README.md | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/README.md b/README.md index 6e9f859..0a62f82 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,100 @@ e.g. [nil nil nil "goodbye" nil]] ``` +### extract + +The whole point of working with sparse arrays is because we wish to work with +interesting subsets of arrays the entirety of which would be too large to +conveniently handle; thus perhaps the most important operation is to be able +to extract a sparse subset of an array. + +`sparse-array.extract/extract ([array function])` + +Return a sparse subset of this `array` - which may be either sparse or +dense - comprising all those cells for which this `function` returns a +'truthy' value. + +e.g. + +```clojure +(extract [[[1 2 3][:one :two :three]["one" "two" "three"]] + [[1 :two "three"]["one" 2 :three][:one "two" 3]] + [[1.0 2.0 3.0][2/2 4/2 6/2]["I" "II" "III"]]] + #(if + (number? %) + (= % 3) + (= (name %) "three"))) + +=> {:dimensions 3, + :coord :i0, + :content (:i1 :i2), + 0 + {:dimensions 2, + :coord :i1, + :content (:i2), + 0 {:dimensions 1, :coord :i2, :content :data, 2 3}, + 1 {:dimensions 1, :coord :i2, :content :data, 2 :three}, + 2 {:dimensions 1, :coord :i2, :content :data, 2 "three"}}, + 1 + {:dimensions 2, + :coord :i1, + :content (:i2), + 0 {:dimensions 1, :coord :i2, :content :data, 2 "three"}, + 1 {:dimensions 1, :coord :i2, :content :data, 2 :three}, + 2 {:dimensions 1, :coord :i2, :content :data, 2 3}}, + 2 + {:dimensions 2, + :coord :i1, + :content (:i2), + 1 {:dimensions 1, :coord :i2, :content :data, 2 3}}} +``` + +### extract-from-dense + +Note that the above example returns the default axis sequence {i0, i1, i2...}; +extracting from a sparse array will always retain the axes of the array +extracted from. Dense arrays, obviously, do not have explicit axes. + +You may wish to specify a sequence of axes when extracting from a dense array. +A function is provided: + +`sparse-array.extract/extract-from-dense ([array function] [array function axes])` + +Return a subset of this dense `array` comprising all those cells for which +this `function` returns a 'truthy' value. Use these `axes` if provided. + +e.g. + +```clojure +(extract-from-dense + [[[1 2 3][:one :two :three]["one" "two" "three"]] + [[1 :two "three"]["one" 2 :three][:one "two" 3]] + [[1.0 2.0 3.0][2/2 4/2 6/2]["I" "II" "III"]]] + integer? + '(:p :q :r)) + +=> {:dimensions 3, + :coord :p, + :content (:q :r), + 0 + {:dimensions 2, + :coord :q, + :content (:r), + 0 {:dimensions 1, :coord :r, :content :data, 0 1, 1 2, 2 3}}, + 1 + {:dimensions 2, + :coord :q, + :content (:r), + 0 {:dimensions 1, :coord :r, :content :data, 0 1}, + 1 {:dimensions 1, :coord :r, :content :data, 1 2}, + 2 {:dimensions 1, :coord :r, :content :data, 2 3}}, + 2 + {:dimensions 2, + :coord :q, + :content (:r), + 1 {:dimensions 1, :coord :r, :content :data, 0 1, 1 2, 2 3}}} +``` + ## License Copyright © 2019 Simon Brooke From d56dca3643a867fd28fdd618f4311a569025bdbb Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Fri, 28 Jun 2019 10:05:24 +0100 Subject: [PATCH 2/4] Upversion to 0.2.1 mainly to test Circle CI integration --- README.md | 4 +++- project.clj | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a62f82..f5547cf 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Arbitrary numbers of dimensions are supported, up to limits imposed by the JVM s [![Clojars Project](https://img.shields.io/clojars/v/sparse-array.svg)](https://clojars.org/sparse-array) +[![CircleCI](https://circleci.com/gh/simon-brooke/sparse-array.svg?style=svg)](https://circleci.com/gh/simon-brooke/sparse-array) + ## Conventions: ### Sparse arrays @@ -210,7 +212,7 @@ e.g. ### extract-from-dense -Note that the above example returns the default axis sequence {i0, i1, i2...}; +Note that the above example returns the default axis sequence `{i0, i1, i2...}`; extracting from a sparse array will always retain the axes of the array extracted from. Dense arrays, obviously, do not have explicit axes. diff --git a/project.clj b/project.clj index 4ffcbee..d36a1dd 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject sparse-array "0.2.0" +(defproject sparse-array "0.2.1" :description "A Clojure library designed to manipulate sparse *arrays* - multi-dimensional spaces accessed by indices, but containing arbitrary values rather than just numbers. For sparse spaces which contain numbers only, you're better to use a *sparse matrix* library, for example [clojure.core.matrix](https://mikera.github.io/core.matrix/)." :url "http://example.com/FIXME" :license {:name "Eclipse Public License" From 5d3b03c600cb091c583df75e26a3e483eb9cf993 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 10 Apr 2023 22:43:28 +0100 Subject: [PATCH 4/4] Upversioned to 0.3.1-SNAPSHOT --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index a94c83c..833de95 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject sparse-array "0.3.0" +(defproject sparse-array "0.3.1-SNAPSHOT" :aot :all :cloverage {:output "docs/cloverage"} :codox {:metadata {:doc "**TODO**: write docs"