Skip to content

Commit

Permalink
Make test/format.scm into an actual test
Browse files Browse the repository at this point in the history
* test/CMakeLists.txt: Test driver.
* README.md: Describe test suite operation.
* cofig/FindGuile.cmake: Needed for test/CMakelists.txt.
* test/format.scm: As stated; check the output sizes.
* test/everything.scm: Renamed from test/test.scm.
  • Loading branch information
lloda committed Jul 13, 2023
1 parent c8d5008 commit 0a6c88b
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/guile-3.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ on:
# - uses: actions/checkout@v3
# - name: test
# run: |
# guile -L mod test/test.scm
# cd test && cmake . && make test
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ The C API shouldn't be affected. Once you get an array handle it makes no sense

Except for the tests and for the pair of functions `ra->array` / `array->ra`, `newra` is independent of the old array system.

`newra` requires Guile 3.0.8. Run the test or the benchmark with
`newra` requires Guile 3.0.8. Run the tests with

```
> cd test && cmake . && make test
```

Run the benchmarks with

```
> $GUILE -L mod test/test.scm
> $GUILE -L mod bench/bench.scm
> $GUILE -L mod -L path-to-guile-ffi-blis bench/bench-blis.scm
```

The manual is at [lloda.github.io/guile-newra](https://lloda.github.io/guile-newra), and you can find some larger examples in `examples/`.

To install the library, copy `mod/newra` and `mod/newra.scm` to somewhere in your Guile load path, and use it with `(import (newra))`.
To install the library, put `mod/newra` and `mod/newra.scm` somewhere in your Guile load path, and use it with `(import (newra))`.

`newra` can use [`guile-ffi-blis`](https://github.com/lloda/guile-ffi-blis) for some functions (`ra-fill!` in the current version), which can provide a considerable speed up for operations with arrays of types `s32`, `u32`, `f32`, `s64`, `u64`, `f64`, `c32`, or `c64` (it can also be slower — there isn't a good heuristic yet). `newra` will test at runtime whether `guile-ffi-blis` is available.

Expand Down
5 changes: 4 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ Help: [C-uc .] insert timestamp [C-cc] flip checkbox [C-uucc] partial flip check

* TODO other [0/1]
* [ ] review definition of (ra-untranspose a i ...). Does it make sense to allow any i < (rank a) ?

* TODO packaging [0/3]
* [ ] Global CMakeLists.txt
* [ ] Autoconf (?)
* [ ] Installation
* TODO replace Guile arrays [0/5]
* [ ] truncated-print support
* [ ] equal? support
Expand Down
105 changes: 105 additions & 0 deletions config/FindGuile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (c) 2008, 2014 OpenCog.org (http://opencog.org)
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# - Try to find Guile; Once done this will define
#
# GUILE_FOUND - system has the GUILE library
# GUILE_INCLUDE_DIRS - the GUILE include directory
# GUILE_LIBRARIES - The libraries needed to use GUILE
# GUILE_VERSION_STRING - Version
# GUILE_SITE_DIR - site dir
# GUILE_EXTENSION_DIR - extension dir
# GUILE_ROOT_DIR - prefix dir

# (lloda) grabbed from https://github.com/stevengj/nlopt/blob/master/cmake/FindGuile.cmake
# added 3.0 to version list
# $GUILE in environment overrides the other searches.

if (NOT "$ENV{GUILE}" STREQUAL "")
set(GUILE "$ENV{GUILE}" CACHE INTERNAL "Copied from environment variable")
get_filename_component(GUILE_ROOT "$ENV{GUILE}" DIRECTORY)
set(GUILE_INCLUDE_DIR_HINT "${GUILE_ROOT}/../include")
set(GUILE_LIB_DIR_HINT "${GUILE_ROOT}/../lib")
endif()

# Look for guile-3.0 first, then 2.2, 2.0, 1.8
# Macports for OSX puts things in /opt/local

# Look for the header file
find_path (GUILE_INCLUDE_DIR libguile.h
PATH_SUFFIXES guile/3.0 guile/2.2 guile/2.0 guile/1.8 libguile guile
HINTS /opt/local/include ${GUILE_INCLUDE_DIR_HINT})

# Look for the library
find_library (GUILE_LIBRARY
NAMES guile-3.0 guile-2.2 guile-2.0 guile
HINTS /opt/local/lib ${GUILE_LIB_DIR_HINT})

set (GUILE_INCLUDE_DIRS ${GUILE_INCLUDE_DIR})
set (GUILE_LIBRARIES ${GUILE_LIBRARY})

# check guile's version if we're using cmake >= 2.6
if (GUILE_INCLUDE_DIR)
SET(GUILE_VERSION_MAJOR 0)
SET(GUILE_VERSION_MINOR 0)
SET(GUILE_VERSION_PATCH 0)

IF(NOT EXISTS "${GUILE_INCLUDE_DIR}/libguile.h")
message("OMG")
ENDIF(NOT EXISTS "${GUILE_INCLUDE_DIR}/libguile.h")

IF(NOT EXISTS "${GUILE_INCLUDE_DIR}/libguile/version.h")
MESSAGE(FATAL_ERROR "Found ${GUILE_INCLUDE_DIR}/libguile.h but not version.h; check your guile installation!")
ENDIF(NOT EXISTS "${GUILE_INCLUDE_DIR}/libguile/version.h")

# Extract the libguile version from the 'version.h' file
SET(GUILE_MAJOR_VERSION 0)
FILE(READ "${GUILE_INCLUDE_DIR}/libguile/version.h" _GUILE_VERSION_H_CONTENTS)

STRING(REGEX MATCH "#define SCM_MAJOR_VERSION[ ]+([0-9])" _MATCH "${_GUILE_VERSION_H_CONTENTS}")
SET(GUILE_VERSION_MAJOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define SCM_MINOR_VERSION[ ]+([0-9]+)" _MATCH "${_GUILE_VERSION_H_CONTENTS}")
SET(GUILE_VERSION_MINOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define SCM_MICRO_VERSION[ ]+([0-9]+)" _MATCH "${_GUILE_VERSION_H_CONTENTS}")
SET(GUILE_VERSION_PATCH ${CMAKE_MATCH_1})

SET(GUILE_VERSION_STRING "${GUILE_VERSION_MAJOR}.${GUILE_VERSION_MINOR}.${GUILE_VERSION_PATCH}")

endif ()

find_program(GUILE_EXECUTABLE
NAMES guile
HINTS ${GUILE_ROOT})
find_program(GUILE_CONFIG_EXECUTABLE
NAMES guile-config
HINTS ${GUILE_ROOT})

if (GUILE_CONFIG_EXECUTABLE)
execute_process (COMMAND ${GUILE_CONFIG_EXECUTABLE} info prefix
OUTPUT_VARIABLE GUILE_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${GUILE_CONFIG_EXECUTABLE} info sitedir
OUTPUT_VARIABLE GUILE_SITE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${GUILE_CONFIG_EXECUTABLE} info extensiondir
OUTPUT_VARIABLE GUILE_EXTENSION_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()

message ("* GUILE_EXECUTABLE: ${GUILE_EXECUTABLE}")
message ("* GUILE_ROOT_DIR: ${GUILE_ROOT_DIR}")
message ("* GUILE_INCLUDE_DIRS: ${GUILE_INCLUDE_DIRS}")
message ("* GUILE_LIBRARIES: ${GUILE_LIBRARIES}")
message ("* GUILE_VERSION_STRING: ${GUILE_VERSION_STRING}")

# handle REQUIRED and QUIET options
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (Guile
REQUIRED_VARS GUILE_EXECUTABLE GUILE_ROOT_DIR GUILE_INCLUDE_DIRS GUILE_LIBRARIES
VERSION_VAR GUILE_VERSION_STRING)

mark_as_advanced (GUILE_INCLUDE_DIR GUILE_LIBRARY)
10 changes: 8 additions & 2 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# -*- coding: utf-8; mode: cmake -*-
# (c) Daniel Llorens - 2018-2019
# docs CMakeLists.txt

# (c) [email protected] 2023
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.

cmake_minimum_required (VERSION 3.5)
project (newra-docs)
project (newra-test)

if (NOT "$ENV{MAKEINFO}" STREQUAL "")
set(MAKEINFO_EXECUTABLE "$ENV{MAKEINFO}" CACHE INTERNAL "Copied from environment variable")
Expand Down
26 changes: 26 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8; mode: cmake -*-
# test CMakeLists.txt

# (c) [email protected] 2019
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.

cmake_minimum_required (VERSION 3.5)
project (newra-test)

include_directories (.)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../config)

# -------------------
# bindings
# -------------------

find_package (Guile REQUIRED)

foreach (target everything format)
add_test (${target} ${GUILE_EXECUTABLE} -q -L "${CMAKE_SOURCE_DIR}/../mod" "${CMAKE_SOURCE_DIR}/${target}.scm")
endforeach ()

enable_testing ()
File renamed without changes.
44 changes: 26 additions & 18 deletions test/format.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,38 @@
; later version.

; Run with $GUILE -L mod test/format.scm
; FIXME actually check something

(import (newra) (newra print) (srfi srfi-64))

(set! test-log-to-file #f)
(test-begin "format")

(for-each
(lambda (ra)
(for-each
(lambda (prefix?)
(for-each
(lambda (compact)
(format #t "\n-------------\nrank ~a compact ~a prefix ~a\n" (ra-rank ra) compact prefix?)
(ra-format ra #:prefix? prefix? #:compact compact)
(ra-format (ra-format ra #f #:prefix? prefix? #:compact compact) #:prefix? #f))
'(0 1 2)))
'(#f #t)))
(list (ra-i)
(ra-i 10)
(ra-i 2 5)
(ra-i 2 2 5)
(ra-i 2 2 2 4)
(ra-i 2 2 2 2 4)))
(define results
(ra-map #t (lambda (ra prefix? compact)
(format #t "\n-------------\nrank ~a compact ~a prefix ~a\n" (ra-rank ra) compact prefix?)
(ra-format ra #:prefix? prefix? #:compact compact)
(let ((sq (ra-format ra #f #:prefix? prefix? #:compact compact)))
(ra-format sq #:prefix? #f)
(ra-dimensions sq)))
(list->ra 1 (list (ra-i)
(ra-i 10)
(ra-i 2 5)
(ra-i 2 2 5)
(ra-i 2 2 2 4)
(ra-i 2 2 2 2 4)))
(ra-transpose (list->ra 1 '(#f #t)) 1)
(ra-transpose (list->ra 1 '(0 1 2)) 2)))

(ra-format results #:compact 1)

(test-assert "size check"
(ra-equal? (list->ra 3 '((((1 1) (1 1) (1 1)) ((2 4) (2 4) (2 4)))
(((1 21) (1 21) (1 10)) ((2 21) (2 21) (2 10)))
(((5 11) (4 11) (2 5)) ((5 11) (4 11) (3 8)))
(((5 26) (4 26) (2 18)) ((5 26) (4 26) (3 18)))
(((9 25) (7 25) (7 19)) ((9 25) (7 25) (7 19)))
(((9 49) (7 49) (7 37)) ((9 49) (7 49) (7 37)))))
results))


; -----------------------
Expand Down

0 comments on commit 0a6c88b

Please sign in to comment.