[genius] Sun Apr 22 23:52:34 2012 Jiri (George) Lebl <jirka 5z com>



commit 46274043c0754999ba4902ab158953f6c305ed3f
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Sun Apr 22 23:52:42 2012 -0500

    Sun Apr 22 23:52:34 2012  Jiri (George) Lebl <jirka 5z com>
    
    	* src/eval.c: avoid linked lists on expanding just one row,
    	  we can do that directly faster.  Improves speed of things
    	  that concatenate things like [a,b,c].  For example sorting.
    
    	* src/geniustests.txt: add some tests

 ChangeLog           |    8 +++++
 src/eval.c          |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/geniustests.txt |    2 +
 3 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1d639a9..63897c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Apr 22 23:52:34 2012  Jiri (George) Lebl <jirka 5z com>
+
+	* src/eval.c: avoid linked lists on expanding just one row,
+	  we can do that directly faster.  Improves speed of things
+	  that concatenate things like [a,b,c].  For example sorting.
+
+	* src/geniustests.txt: add some tests
+
 Sun Apr 22 17:53:07 2012  Jiri (George) Lebl <jirka 5z com>
 
 	* src/structs.h, src/eval.c: MatrixRow tree node is also
diff --git a/src/eval.c b/src/eval.c
index 10baa85..6a3d1a3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1175,6 +1175,89 @@ mat_need_expand (GelMatrixW *m)
 	return FALSE;
 }
 
+/* we know we are a row matrix */
+static void
+quick_wide_expand (GelETree *n)
+{
+	GelMatrix *m;
+	int h, w, i, j;
+	GelMatrixW *nm = n->mat.matrix;
+
+	h = 0;
+	w = 0;
+	for (i = 0; i < gel_matrixw_width (nm); i++) {
+		GelETree *et = gel_matrixw_get_index (nm, i, 0);
+		if (et == NULL) {
+			if (h <= 0)
+				h = 1;
+			w++;
+		} else if (et->type == GEL_MATRIX_NODE) {
+			if (gel_matrixw_height (et->mat.matrix) > h)
+				h = gel_matrixw_height (et->mat.matrix);
+			w += gel_matrixw_width (et->mat.matrix);
+		} else if (et->type != GEL_NULL_NODE) {
+			if (h <= 0)
+				h = 1;
+			w++;
+		}
+	}
+
+	gel_matrixw_make_private (nm, FALSE /* kill_type_caches */);
+
+	m = gel_matrix_new();
+	gel_matrix_set_size(m, w, h, TRUE /* padding */);
+
+	j = 0;
+	for (i = 0; i < gel_matrixw_width (nm); i++) {
+		GelETree *et = gel_matrixw_get_index (nm, i, 0);
+		if (et == NULL) {
+			j++;
+		} else if (et->type == GEL_MATRIX_NODE) {
+			int hh = gel_matrixw_height (et->mat.matrix);
+			int ww = gel_matrixw_width (et->mat.matrix);
+			int ii, jj;
+			GelMatrixW *mm = et->mat.matrix;
+
+			gel_matrixw_make_private (mm,
+						  FALSE /* kill_type_caches */);
+
+			for (ii = 0; ii < ww; ii++) {
+				int jjj;
+				for (jj = 0; jj < hh; jj++) {
+					GelETree *e = 
+						gel_matrixw_get_index (mm, ii, jj);
+					gel_matrix_index (m, j+ii, jj) = e;
+					gel_matrixw_set_index (mm, ii, jj) = NULL;
+				}
+				jjj = 0;
+				for (; jj < h; jj++) {
+					GelETree *e = 
+						gel_matrix_index (m, j+ii, jjj);
+					if (e != NULL)
+						gel_matrix_index (m, j+ii, jj) = gel_copynode (e);
+					if (++jjj >= hh)
+						jjj = 0;
+				}
+			}
+			j += ww;
+		} else if (et->type != GEL_NULL_NODE) {
+			int jj;
+			gel_matrixw_set_index (nm, i, 0) = NULL;
+			gel_matrix_index (m, j, 0) = et;
+			for (jj = 1; jj < h; jj++) {
+				gel_matrix_index (m, j, jj) = gel_copynode (et);
+			}
+			j++;
+		}
+	}
+
+	freetree_full (n, TRUE, FALSE);
+
+	n->type = GEL_MATRIX_NODE;
+	n->mat.matrix = gel_matrixw_new_with_matrix (m);
+	n->mat.quoted = FALSE;
+}
+
 /*evaluate a matrix (or try to), it will try to expand the matrix and
   put 0's into the empty, undefined, spots. For example, a matrix such
   as if b = [8,7]; a = [1,2:3,b]  should expand to, [1,2,2:3,8,7] */
@@ -1223,6 +1306,11 @@ gel_expandmatrix (GelETree *n)
 		/* never should be reached */
 	}
 
+	if (h == 1) {
+		quick_wide_expand (n);
+		return;
+	}
+
 	gel_matrixw_make_private (nm, FALSE /* kill_type_caches */);
 
 	m = gel_matrix_new();
diff --git a/src/geniustests.txt b/src/geniustests.txt
index fbbe7a2..4b92489 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -1109,6 +1109,8 @@ prod n=1 to 20 do (A=randint(10,3,7)-4*ones(3,7);IsPositiveSemidefinite(A'*A))	t
 prod n=1 to 20 do (A=randint(10,7,7)-4*ones(7,7);(rank(A'*A) < 7) or IsPositiveDefinite(A'*A))	true
 sinc(0)==1							true
 sinc(5)==sin(5)/5						true
+A=[1;2];B=[3;4;5;6;7];[A,B,0,null,4]+""				"[1,3,0,4;2,4,0,4;1,5,0,4;2,6,0,4;1,7,0,4]"
+A=[1,2;3,4];B=[5;6;7];[A,B]+""					"[1,2,5;3,4,6;1,2,7]"
 load "nullspacetest.gel"					true
 load "longtest.gel"						true
 load "testprec.gel"						true



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]