~dieggsy/chicken-genann

9cd54b6bcfec38fb00c43f79f7b77038253fae58 — dieggsy 3 years ago 750d311 0.2.2
Add genann-weights, ensure bounds for ref/set
3 files changed, 38 insertions(+), 8 deletions(-)

M genann.release-info
M genann.scm
M genann.svnwiki
M genann.release-info => genann.release-info +1 -0
@@ 1,6 1,7 @@
;; -*- mode: scheme -*-
(repo git "git://github.com/dieggsy/genann.git")
(uri targz "https://github.com/dieggsy/genann/archive/{egg-release}.tar.gz")
(release "0.2.2")
(release "0.2.1")
(release "0.2.0")
(release "0.1.0")

M genann.scm => genann.scm +35 -8
@@ 6,22 6,24 @@
                genann-read
                genann-write
                genann-run
                genann-inputs
                genann-hidden-layers
                genann-hidden-neurons
                genann-outputs
                genann-total-weights
                genann-weights

                ;; Added
                genann-init*
                make-genann
                genann-copy*
                genann?
                genann-inputs
                genann-hidden-layers
                genann-hidden-neurons
                genann-outputs
                genann-total-weights
                genann-weight-ref
                genann-weight-set!)

  (import scheme
          chicken.foreign
          chicken.fixnum
          (only chicken.file.posix
                port->fileno
                file-close


@@ 125,13 127,38 @@
    (foreign-lambda* int ((genann ann))
      "C_return(ann->total_weights);"))

  (define genann-weight-set!
  (define %genann-weights
    (foreign-lambda* (c-pointer double) ((genann ann))
      "C_return(ann->weight);"))

  (define (genann-weights ann)
    (let* ((len (genann-total-weights ann))
           (out (make-f64vector len))
           (res (%genann-weights ann)))
      (move-memory! res
                    out
                    (* len (foreign-value "sizeof(double)" size_t)))
      out))

  (define (genann-weight-set! ann i x)
    (assert (fx< i (genann-total-weights ann))
            'genann-weight-set!
            "out of range"
            (genann-weights ann)
            i)
    (foreign-lambda* void ((genann ann) (size_t i) (double x))
      "ann->weight[i] = x;"))

  (define genann-weight-ref
    (getter-with-setter
     (foreign-lambda* double ((genann ann) (size_t i))
       "C_return(ann->weight[i]);")
     (lambda (ann i)
       (assert (fx< i (genann-total-weights ann))
               'genann-weight-ref
               "out of range"
               (genann-weights ann)
               i)
       ((foreign-lambda* double ((genann ann) (size_t i))
          "C_return(ann->weight[i]);")
        ann i))
     genann-weight-set!)))


M genann.svnwiki => genann.svnwiki +2 -0
@@ 55,6 55,7 @@ genann so it can be properly garbage collected.
<procedure>(genann-hidden-neurons genann)</procedure>
<procedure>(genann-outputs genann)</procedure>
<procedure>(genann-total-weights genann)</procedure>
<procedure>(genann-weights genann)</procedure>
Returns number of inputs, hidden layers, hidden neurons per layer, and outputs,
respectively, in {{genann}}. These are more or less equivalent to the following
in C:


@@ 65,6 66,7 @@ genann->hidden_layers
genann->hidden
genann->outputs
genann->total_weights
gennan->weight
</enscript>

<procedure>(genann-weight-set! genann i x)</procedure>