From 7cb6488decdd14e6fb245e23f2af5bc868cbbcde Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Sun, 21 Feb 2021 11:21:34 +0100 Subject: [PATCH 1/4] Move jtisempty to a cpp file For now it's a direct copy of the original C code, with a nodiscard added to be on the safe side. --- jsrc/CMakeLists.txt | 1 + jsrc/verbs/monadic/isempty.cpp | 7 +++++++ jsrc/verbs/v.c | 6 ------ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 jsrc/verbs/monadic/isempty.cpp diff --git a/jsrc/CMakeLists.txt b/jsrc/CMakeLists.txt index 7c91ae9f..80f4d083 100644 --- a/jsrc/CMakeLists.txt +++ b/jsrc/CMakeLists.txt @@ -73,6 +73,7 @@ target_sources(j PRIVATE verbs/vsb.c verbs/vx.c verbs/vz.c + verbs/monadic/isempty.cpp verbs/monadic/rank.cpp verbs/monadic/same.cpp verbs/monadic/shape.cpp diff --git a/jsrc/verbs/monadic/isempty.cpp b/jsrc/verbs/monadic/isempty.cpp new file mode 100644 index 00000000..ce7e2ec7 --- /dev/null +++ b/jsrc/verbs/monadic/isempty.cpp @@ -0,0 +1,7 @@ +#include "array.hpp" + +[[nodiscard]] A +jtisempty(J jt, A w) { + if ((AT(w) & SPARSE) != 0) return jteps(jt, num(0), shape(jt, w)); + return AN(w) == 0 ? jtrue : jfalse; +} // 0 e. $ diff --git a/jsrc/verbs/v.c b/jsrc/verbs/v.c index e73ee98b..1e71c02b 100644 --- a/jsrc/verbs/v.c +++ b/jsrc/verbs/v.c @@ -4,12 +4,6 @@ /* Verbs */ #include "j.h" - -A -jtisempty(J jt, A w) { - if ((AT(w) & SPARSE) != 0) return jteps(jt, num(0), shape(jt, w)); - return AN(w) == 0 ? jtrue : jfalse; -} // 0 e. $ A jtisnotempty(J jt, A w) { if ((AT(w) & SPARSE) != 0) return jtnot(jt, jteps(jt, num(0), shape(jt, w))); From 8ba4852388310c325cfa26229b4c0ea377c9d80a Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Sun, 21 Feb 2021 11:28:22 +0100 Subject: [PATCH 2/4] Restructure jtisempty to use preferred layout * Replace `A` with `array` * Use trailing return types --- jsrc/verbs/monadic/isempty.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsrc/verbs/monadic/isempty.cpp b/jsrc/verbs/monadic/isempty.cpp index ce7e2ec7..d4e7b8ac 100644 --- a/jsrc/verbs/monadic/isempty.cpp +++ b/jsrc/verbs/monadic/isempty.cpp @@ -1,7 +1,7 @@ #include "array.hpp" -[[nodiscard]] A -jtisempty(J jt, A w) { +[[nodiscard]] auto +jtisempty(J jt, array w) -> array { if ((AT(w) & SPARSE) != 0) return jteps(jt, num(0), shape(jt, w)); return AN(w) == 0 ? jtrue : jfalse; } // 0 e. $ From 6392a5afb2a002b234de3660f8fb0e3f57587855 Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Sun, 21 Feb 2021 11:30:45 +0100 Subject: [PATCH 3/4] Improve documentation for jtisempty --- jsrc/verbs/monadic/isempty.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jsrc/verbs/monadic/isempty.cpp b/jsrc/verbs/monadic/isempty.cpp index d4e7b8ac..39a87742 100644 --- a/jsrc/verbs/monadic/isempty.cpp +++ b/jsrc/verbs/monadic/isempty.cpp @@ -1,7 +1,15 @@ #include "array.hpp" +/** @file */ + +/** + * @brief `0 e. $` IsEmpty + * @param jt JST (J Syntax Tree) + * @param w Input aray + * @return boolean jtrue or jfalse + */ [[nodiscard]] auto jtisempty(J jt, array w) -> array { if ((AT(w) & SPARSE) != 0) return jteps(jt, num(0), shape(jt, w)); return AN(w) == 0 ? jtrue : jfalse; -} // 0 e. $ +} From 9bec2a82f59e0518c0994121fc7c9dd3c0883351 Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Sun, 21 Feb 2021 11:57:30 +0100 Subject: [PATCH 4/4] Use is_sparse method --- jsrc/verbs/monadic/isempty.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsrc/verbs/monadic/isempty.cpp b/jsrc/verbs/monadic/isempty.cpp index 39a87742..fd82c93c 100644 --- a/jsrc/verbs/monadic/isempty.cpp +++ b/jsrc/verbs/monadic/isempty.cpp @@ -10,6 +10,6 @@ */ [[nodiscard]] auto jtisempty(J jt, array w) -> array { - if ((AT(w) & SPARSE) != 0) return jteps(jt, num(0), shape(jt, w)); + if (is_sparse(w)) return jteps(jt, num(0), shape(jt, w)); return AN(w) == 0 ? jtrue : jfalse; }