gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat
-rw-r--r--matrix-quicksort.lua 31
-rw-r--r--matrix.lua 1
2 files changed, 32 insertions, 0 deletions
diff --git a/matrix-quicksort.lua b/matrix-quicksort.lua
new file mode 100644
index 00000000..111973ad
--- /dev/null
+++ b/matrix-quicksort.lua
@@ -0,0 +1,31 @@
+
+local function quicksort_array(m, f)
+ local t = m.data
+
+ local function quicksort(start, endi)
+ if start >= endi then return end
+ local pivot = start
+ for i = start + 1, endi do
+ if f(t[i], t[pivot]) then
+ local temp = t[pivot + 1]
+ t[pivot + 1] = t[pivot]
+ if(i == pivot + 1) then
+ t[pivot] = temp
+ else
+ t[pivot] = t[i]
+ t[i] = temp
+ end
+ pivot = pivot + 1
+ end
+ end
+
+ quicksort(start, pivot - 1)
+ quicksort(pivot + 1, endi)
+ end
+
+ local n, ncols = m:dim()
+ assert(ncols == 1, "expecting column matrix")
+ quicksort(0, n - 1)
+end
+
+return quicksort_array
diff --git a/matrix.lua b/matrix.lua
index d7c5e75b..5e5e3c8f 100644
--- a/matrix.lua
+++ b/matrix.lua
@@ -686,6 +686,7 @@ local matrix_methods = {
norm = matrix_norm,
norm2 = matrix_norm2,
slice = matrix_slice,
+ sort = require("matrix-quicksort"),
show = matrix_display_gen(mat_real_get),
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月15日 20:32:23 +0000

AltStyle によって変換されたページ (->オリジナル) /