head	1.1;
access;
symbols;
locks; strict;
comment	@ * @;


1.1
date	94.07.01.01.18.05;	author rjj;	state Exp;
branches;
next	;


desc
@Initial implementation for the Hopfield Neural Network algorithm.  Buggy!
@


1.1
log
@Initial revision
@
text
@// convert-hopfield-images.c

#include "convert-hopfield-images.h"


// Convert any dimension image to a 1-D image,
//   the values will be in  point set iteration order.
//
IA_Image<IA_Point<int>,int>
convert_to_1D( const IA_Image<IA_Point<int>,int> & idi ) {

    return
	IA_Image<IA_Point<int>,int>(
	    IA_boxy_pset( IA_Point<int>( 0 ),
			  IA_Point<int>( idi.domain().card() - 1 ) ),
	    idi.value_array().data_start(),
	    idi.domain().card()
	    );
}


// Convert a 1-D image into a 2-D image by using the same data
//   values, in the same order, but with a boxy point set.
//
IA_Image<IA_Point<int>,int>
convert_to_2D( const IA_Image<IA_Point<int>,int> & idi_1D,
	       int width )
{
    if ( idi_1D.domain().dim() != 1 ) {
	ia_throw( IA::INVALID_OPERATION, __FILE__, __LINE__ );
	return idi_1D;
    }

    int n = idi_1D.domain().card(), rows = n/width;

    if ( rows*width != n ) {
	cerr << "Cannot convert image of length: " << n
	     << " as image of width: " << width 
	     << " and with rows: " << rows << endl;
	return idi_1D;
    }

    // Reshape the image to be 2-d
    return
	IA_Image<IA_Point<int>,int>(
	    IA_boxy_pset( IA_Point<int>(0,0),
			  IA_Point<int>(rows-1,width-1) ),
	    idi_1D.value_array().data_start(),
	    n );
}


@
