comp.lang.ada
 help / color / mirror / Atom feed
* Passing arrays as record fields
@ 1997-06-12  0:00 Mark J Gallagher
  1997-06-13  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 3+ messages in thread
From: Mark J Gallagher @ 1997-06-12  0:00 UTC (permalink / raw)



Please forgive me if I am overlooking something very obvious, but:

I am attemting to implement a back-propagated feed-forward neural
network in ADA 95 using the latest release of gnat. I have a record
defined as

  type Count_t is Integer range 0 .. Integer'Last;
  type Count_a is array (Integer range <>) of Count_t;
  type Net_t(... N_Neurons: Count_t ...) is record
    ...
    Neuron_Counts: Count_a(N_Neurons);
    ...
  end record;

and a procedure

  procedure Initialise(Net: in out Net_t);

I can declare a variable Net of type Net_t and assign an array to the
Neuron_Counts field, which I can read from the block in which Net has
been declared. However, when I attempt to read the array from the
procedure Initialise, I get garbage. Help!




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Passing arrays as record fields
  1997-06-12  0:00 Passing arrays as record fields Mark J Gallagher
@ 1997-06-13  0:00 ` Matthew Heaney
  1997-06-14  0:00   ` Robert Dewar
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 1997-06-13  0:00 UTC (permalink / raw)



In article <33A00D4C.F4E@taz.dra.hmg.gb>, Mark J Gallagher
<mjgallagher@taz.dra.hmg.gb> wrote:


>  type Count_t is Integer range 0 .. Integer'Last;
>  type Count_a is array (Integer range <>) of Count_t;
>  type Net_t(... N_Neurons: Count_t ...) is record
>    ...
>    Neuron_Counts: Count_a(N_Neurons);
>    ...
>  end record;
>
>and a procedure
>
>  procedure Initialise(Net: in out Net_t);
>
>I can declare a variable Net of type Net_t and assign an array to the
>Neuron_Counts field, which I can read from the block in which Net has
>been declared. However, when I attempt to read the array from the
>procedure Initialise, I get garbage. Help!

A few points:

If you just need a "count" type, use the predefined type Natural.

Do you want you neural net type to be constrained or unconstrained?  That
is, should neural net objects be mutable or not?

Try this:

type Natural_Array is array (Positive range <>) of Natural;

subtype Neural_Net_Length_Range is 
   Natural range 0 .. 100;  -- or whatever max is appropriate

type Neural_Net (Length : Neural_Net_Length_Range := 0) is
   record
      Counts : Natural_Array (1 .. Length);
   end record;

I know nothing about neural nets, so you may need to do some more
explaining before I totally understand your problem.

What is the purpose of Initialize?  Does it set the count?  Or does it
merely read the count specified by the client?  The former means the neural
net type is mutable, the latter that mutability is optional.

And what I mean by mutability is, Is the subtype definate?  An indefinate
subtype (without a default value for the discriminant) would have to be
constrained by the client (unless of course the Initialize subprogram were
a function, in which case the subprogram could define the constraint).

Tell me more about what Initialize is trying to do, and be more specific
about the problems you're having.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Passing arrays as record fields
  1997-06-13  0:00 ` Matthew Heaney
@ 1997-06-14  0:00   ` Robert Dewar
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1997-06-14  0:00 UTC (permalink / raw)



<<<mjgallagher@taz.dra.hmg.gb> wrote:
 
 
>  type Count_t is Integer range 0 .. Integer'Last;
>  type Count_a is array (Integer range <>) of Count_t;
>  type Net_t(... N_Neurons: Count_t ...) is record
>    ...
>    Neuron_Counts: Count_a(N_Neurons);
>    ...
>  end record;
>
>and a procedure
>
>  procedure Initialise(Net: in out Net_t);>>



I am certainly much less of a fanatic on the issue of avoiding the use of
predefined types like Integer than many others, but the above declarations
seem to use Integer quite gratuitously. Surely the bound that is spelled
as Integer'Last in the above should be a value driven by the design of
the abstraction???





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-06-14  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-12  0:00 Passing arrays as record fields Mark J Gallagher
1997-06-13  0:00 ` Matthew Heaney
1997-06-14  0:00   ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox