fix confusion
This commit is contained in:
parent
d05d4c920d
commit
e72ce435d9
@ -1,94 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2006 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: matrices.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: Have some fun with blobs *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/*
|
||||
A matrix is an object with integer or floating point numbers. A matrix
|
||||
may have a number of dimensions. These routines implement a number of
|
||||
routine manipulation procedures.
|
||||
|
||||
matrix(Type,D1,D2,...,Dn,data(......))
|
||||
|
||||
Type = int, float
|
||||
*/
|
||||
|
||||
:- module( matrices,
|
||||
[
|
||||
matrix_new/4,
|
||||
matrix_dim/2,
|
||||
matrix_type/2,
|
||||
matrix_max/2,
|
||||
matrix_add/3]).
|
||||
|
||||
:- use_module(library_lists,
|
||||
[append/3]).
|
||||
|
||||
matrix_new(Type,Dims,Data,Matrix) :-
|
||||
PackedData =.. [data|Data],
|
||||
append([Type,Dims],PackedData,MatInfo),
|
||||
Matrix =.. [matrix|MatInfo].
|
||||
|
||||
matrix_dim(Matrix,Dim) :-
|
||||
functor(Matrix,matrix,Arity),
|
||||
Dim is Arity-2.
|
||||
|
||||
matrix_type(Matrix,Type) :-
|
||||
arg(1, Matrix, Type).
|
||||
Dim is Arity-2.
|
||||
|
||||
matrix_max(Matrix,Max) :-
|
||||
arg(1, Matrix, Type).
|
||||
typed_matrix_max(Type, Matrix, Max).
|
||||
|
||||
typed_matrix_max(int, Matrix, Max) :-
|
||||
int_max_of_matrix(Matrix, Max, _).
|
||||
typed_matrix_max(float, Matrix, Max) :-
|
||||
float_max_of_matrix(Matrix, Max, _).
|
||||
|
||||
|
||||
matrix_maxarg(Matrix,Max) :-
|
||||
arg(1, Matrix, Type).
|
||||
typed_matrix_maxarg(Type, Matrix, Max).
|
||||
|
||||
typed_matrix_maxarg(int, Matrix, Max) :-
|
||||
int_max_of_matrix(Matrix, _, Max).
|
||||
typed_matrix_maxarg(float, Matrix, Max) :-
|
||||
float_max_of_matrix(Matrix, _, Max).
|
||||
|
||||
|
||||
matrix_min(Matrix,Min) :-
|
||||
arg(1, Matrix, Type).
|
||||
typed_matrix_min(Type, Matrix, Min).
|
||||
|
||||
typed_matrix_min(int, Matrix, Min) :-
|
||||
int_min_of_matrix(Matrix, Min, _).
|
||||
typed_matrix_min(float, Matrix, Min) :-
|
||||
float_min_of_matrix(Matrix, Min, _).
|
||||
|
||||
|
||||
matrix_minarg(Matrix,Min) :-
|
||||
arg(1, Matrix, Type).
|
||||
typed_matrix_minarg(Type, Matrix, Min).
|
||||
|
||||
typed_matrix_minarg(int, Matrix, Min) :-
|
||||
int_min_of_matrix(Matrix, _, Min).
|
||||
typed_matrix_minarg(float, Matrix, Min) :-
|
||||
float_min_of_matrix(Matrix, _, Min).
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,60 +0,0 @@
|
||||
#
|
||||
# default base directory for YAP installation
|
||||
# (EROOT for architecture-dependent files)
|
||||
#
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
ROOTDIR = $(prefix)
|
||||
EROOTDIR = @exec_prefix@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
#
|
||||
# where the binary should be
|
||||
#
|
||||
BINDIR = $(EROOTDIR)/bin
|
||||
#
|
||||
# where YAP should look for libraries
|
||||
#
|
||||
LIBDIR=@libdir@/Yap
|
||||
#
|
||||
#
|
||||
CC=@CC@
|
||||
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
#
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
SHELL=/bin/sh
|
||||
RANLIB=@RANLIB@
|
||||
srcdir=@srcdir@
|
||||
SHLIB_CFLAGS=@SHLIB_CFLAGS@
|
||||
SO=@SO@
|
||||
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
|
||||
CWD=$(PWD)
|
||||
#
|
||||
|
||||
OBJS=matrix.o
|
||||
SOBJS=matrix.@SO@
|
||||
|
||||
#in some systems we just create a single object, in others we need to
|
||||
# create a libray
|
||||
|
||||
all: $(SOBJS)
|
||||
|
||||
matrix.o: $(srcdir)/matrix.c
|
||||
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/matrix.c -o matrix.o
|
||||
|
||||
@DO_SECOND_LD@%.@SO@: %.o
|
||||
@DO_SECOND_LD@ @SHLIB_LD@ -o $@ $<
|
||||
|
||||
@DO_SECOND_LD@matrix.@SO@: matrix.o
|
||||
@DO_SECOND_LD@ @SHLIB_LD@ -o matrix.@SO@ matrix.o
|
||||
|
||||
install: all
|
||||
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(LIBDIR)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK
|
||||
|
@ -1,150 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: random.c *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: regular expression interpreter *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include "YapInterface.h"
|
||||
#include <math.h>
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void PROTO(init_matrices, (void));
|
||||
|
||||
static int
|
||||
int_min_of_matrix(void)
|
||||
{
|
||||
Term t = YAP_ARG1;
|
||||
YAP_UInt dim = YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)), i, pos;
|
||||
YAP_Int *mat = (YAP_Int *)malloc( dim*sizeof(YAP_Int) ), min;
|
||||
if (!mat)
|
||||
return FALSE;
|
||||
if (!YAP_ArgsToIntArray(t, dim, mat))
|
||||
return FALSE;
|
||||
|
||||
min = mat[0];
|
||||
pos = 0;
|
||||
for (i = 1; i < dim; i++) {
|
||||
if (mat[i] < min) {
|
||||
min = mat[i];
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
return YAP_unify(YAP_ARG2, YAP_MkIntTerm(min)) &&
|
||||
YAP_unify(YAP_ARG3, YAP_MkIntTerm(pos));
|
||||
}
|
||||
|
||||
static int
|
||||
float_min_of_matrix(void)
|
||||
{
|
||||
Term t = YAP_ARG1;
|
||||
YAP_UInt dim = YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)), i, pos;
|
||||
YAP_Float *mat = (YAP_Float *)malloc( dim*sizeof(YAP_Float) ), min;
|
||||
|
||||
if (!mat)
|
||||
return FALSE;
|
||||
if (!YAP_ArgsToFloatArray(t, dim, mat))
|
||||
return FALSE;
|
||||
|
||||
min = mat[0];
|
||||
pos = 0;
|
||||
for (i = 1; i < dim; i++) {
|
||||
if (mat[i] < min) {
|
||||
min = mat[i];
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
return YAP_unify(YAP_ARG2, YAP_MkFloatTerm(min)) &&
|
||||
YAP_unify(YAP_ARG3, YAP_MkIntTerm(pos));
|
||||
}
|
||||
|
||||
static int
|
||||
int_max_of_matrix(void)
|
||||
{
|
||||
Term t = YAP_ARG1;
|
||||
YAP_UInt dim = YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)), i, pos;
|
||||
YAP_Int *mat = (YAP_Int *)malloc( dim*sizeof(YAP_Int) ), max;
|
||||
|
||||
if (!mat)
|
||||
return FALSE;
|
||||
if (!YAP_ArgsToIntArray(t, dim, mat))
|
||||
return FALSE;
|
||||
|
||||
max = mat[0];
|
||||
pos = 0;
|
||||
for (i = 1; i < dim; i++) {
|
||||
if (mat[i] > max) {
|
||||
max = mat[i];
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
return YAP_unify(YAP_ARG2, YAP_MkIntTerm(min)) &&
|
||||
YAP_unify(YAP_ARG3, YAP_MkIntTerm(pos));
|
||||
}
|
||||
|
||||
static int
|
||||
float_max_of_matrix(void)
|
||||
{
|
||||
Term t = YAP_ARG1;
|
||||
YAP_UInt dim = YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)), i, pos;
|
||||
YAP_Float *mat = (YAP_Float *)malloc( dim*sizeof(YAP_Float) ), max;
|
||||
|
||||
if (!mat)
|
||||
return FALSE;
|
||||
if (!YAP_ArgsToFloatArray(t, dim, mat))
|
||||
return FALSE;
|
||||
|
||||
max = mat[0];
|
||||
pos = 0;
|
||||
for (i = 1; i < dim; i++) {
|
||||
if (mat[i] > max) {
|
||||
max = mat[i];
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
return YAP_unify(YAP_ARG2, YAP_MkFloatTerm(min)) &&
|
||||
YAP_unify(YAP_ARG3, YAP_MkIntTerm(pos));
|
||||
}
|
||||
|
||||
void
|
||||
init_matrices(void)
|
||||
{
|
||||
YAP_UserCPredicate("int_max_of_matrix", int_max_of_matrix, 3);
|
||||
YAP_UserCPredicate("float_max_of_matrix", float_max_of_matrix, 3);
|
||||
YAP_UserCPredicate("int_min_of_matrix", int_min_of_matrix, 3);
|
||||
YAP_UserCPredicate("float_min_of_matrix", float_min_of_matrix, 3);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
int WINAPI PROTO(win_matrices, (HANDLE, DWORD, LPVOID));
|
||||
|
||||
int WINAPI win_matrices(HANDLE hinst, DWORD reason, LPVOID reserved)
|
||||
{
|
||||
switch (reason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user