AI-LibNeural

 view release on metacpan or  search on metacpan

LibNeural.xs  view on Meta::CPAN

	if (strEQ(name + 0, "ALL")) {	/*  removed */
#ifdef ALL
	    return ALL;
#else
	    goto not_there;
#endif
	}
    case 'H':
	if (strEQ(name + 0, "HIDDEN")) {	/*  removed */
#ifdef HIDDEN
	    return HIDDEN;
#else
	    goto not_there;
#endif
	}
    case 'I':
	if (strEQ(name + 0, "INPUT")) {	/*  removed */
#ifdef INPUT
	    return INPUT;
#else
	    goto not_there;
#endif
	}
    case 'O':
	if (strEQ(name + 0, "OUTPUT")) {	/*  removed */
#ifdef OUTPUT
	    return OUTPUT;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

/* function that takes an array reference and convert it into an equivelent
 * float array. dlen is the number of elements that we want to make sure are in
 * the array */
static float *
svpvav_to_float_array (SV * svpvav, int dlen)
{
	float *  array;
	AV    *  avp;
	SV    ** svpp;
	int      i;

	/* make sure that svpvav is array reference */
	if( !SvROK(svpvav) || (SvTYPE(SvRV(svpvav)) != SVt_PVAV) )
		Perl_croak(aTHX_ "parameter should be a valid array reference");

	/* get the array pointers out of its sv reference */
	avp = (AV*)SvRV(svpvav);

	/* make sure that it has the desired number of elements */
	if( av_len(avp)+1 != dlen )
		Perl_croak(aTHX_ "size of array and desired length do not match");
	
	/* alloc the memory for ains and aouts */
	array = (float*)malloc( dlen * sizeof(float) );
	if( array == NULL )
		Perl_croak(aTHX_ "unable to allocate memory for storing array");

	/* copy avins to ains */
	for( i = 0; i < dlen; i++ )
	{
		/* don't need ins anymore use as a tmp */
		svpp = av_fetch(avp, i, 0);
		if( !svpp || !*svpp || !SvOK(*svpp) )
		{
			if( array ) free(array);
			Perl_croak(aTHX_ "bad array value encountered at index %d", i);
		}
		array[i] = (float)SvNV(*svpp);
	}

	return array;
}

MODULE = AI::LibNeural		PACKAGE = AI::LibNeural		

double
constant(sv,arg)
    PREINIT:
	STRLEN		len;
    INPUT:
	SV *		sv
	char *		s = SvPV(sv, len);
	int		arg
    CODE:
	RETVAL = constant(s,len,arg);
    OUTPUT:
	RETVAL

nnwork *
nnwork::new (...)
    PREINIT:
	char * filename;
	int    inputs;
	int    hiddens;
	int    outputs;
    CODE:
    	CLASS = (char*)SvPV_nolen(ST(0));

	if( items == 1 )
	{
		/* blank */
		RETVAL = new nnwork();
	}
	else if( items == 2 )
	{
		/* given a file to load */
		char*	filename = (char*)SvPV_nolen(ST(1));
		RETVAL = new nnwork(filename);
	}
	else if( items == 4 )
	{



( run in 0.965 second using v1.01-cache-2.11-cpan-39bf76dae61 )