guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] branch master updated: Fix bug in new array reader


From: Daniel Llorens
Subject: [Guile-commits] branch master updated: Fix bug in new array reader
Date: Wed, 03 Mar 2021 12:44:51 -0500

This is an automated email from the git hooks/post-receive script.

lloda pushed a commit to branch master
in repository guile.

The following commit(s) were added to refs/heads/master by this push:
     new 9516a10  Fix bug in new array reader
9516a10 is described below

commit 9516a10ab39d51c73b6355f7d8cd4188a2e461b4
Author: Daniel Llorens <lloda@sarc.name>
AuthorDate: Wed Mar 3 18:40:39 2021 +0100

    Fix bug in new array reader
    
    * module/ice-9/read.scm (read-array): Return pair for dimension when len
      is given; single number is lbnd for list->typed-array.
    * test-suite/tests/arrays.test: More test cases for the reader.
---
 module/ice-9/read.scm        |  6 ++----
 test-suite/tests/arrays.test | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/module/ice-9/read.scm b/module/ice-9/read.scm
index 7f79bf9..9e3346c 100644
--- a/module/ice-9/read.scm
+++ b/module/ice-9/read.scm
@@ -507,10 +507,8 @@
           (error "unexpected end of input while reading array"))
         (values ch
                 (if len
-                    (if (zero? lbnd)
-                        len
-                        (list lbnd (+ lbnd (1- len))))
-                    lbnd))))
+                  (list lbnd (+ lbnd (1- len)))
+                  lbnd))))
     (define (read-shape ch alt)
       (if (memv ch '(#\@ #\:))
           (let*-values (((ch head) (read-dimension ch))
diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test
index c8eed39..c2716ed 100644
--- a/test-suite/tests/arrays.test
+++ b/test-suite/tests/arrays.test
@@ -994,7 +994,7 @@
 ;;; printing arrays
 ;;;
 
-(with-test-prefix/c&e "printing and reading arrays"
+(with-test-prefix/c&e "printing arrays"
   (pass-if-equal "writing 1D arrays that aren't vectors"
     "#1(b c)"
     (format #f "~a" (make-shared-array #(a b c)
@@ -1057,3 +1057,37 @@
       "#3@1@-1@1(((1)) ((1)) ((1)))"
       (format #f "~a" (make-array 1 '(1 3) '(-1 -1) '(1 1)))))
 
+;;;
+;;; reading arrays
+;;;
+
+(with-test-prefix/c&e "reading arrays"
+  
+  (pass-if "empty 3-array with first nonempty dim I"
+    (array-equal? (make-array 1 1 0 0)
+                  (call-with-input-string "#3(())" read)))
+  (pass-if "empty 3-array with first nonempty dim II"
+    (array-equal? (make-array 1 1 0 0)
+                  #3(())))
+  
+  (pass-if "empty 3-array with middle nonempty dim I"
+    (array-equal? (make-array 1 0 1 0)
+                  (call-with-input-string "#3:0:1:0()" read)))
+  (pass-if "empty 3-array with middle nonempty dim II"
+    (array-equal? (make-array 1 0 1 0)
+                  #3:0:1:0()))
+
+  (pass-if "empty typed 3-array with middle nonempty dim I"
+    (array-equal? (make-typed-array 'f64 1 0 1 0)
+                  (call-with-input-string "#3f64:0:1:0()" read)))
+  (pass-if "empty typed 3-array with middle nonempty dim II"
+    (array-equal? (make-typed-array 'f64 1 0 1 0)
+                  #3f64:0:1:0()))
+
+  (pass-if "array with specified size I"
+    (array-equal? #f64(1 2 3)
+                  (call-with-input-string "#f64:3(1 2 3)" read)))
+  (pass-if "array with specified size II"
+    (array-equal? #f64(1 2 3)
+                  #f64:3(1 2 3))))
+  



reply via email to

[Prev in Thread] Current Thread [Next in Thread]