| Did you know ... | Search Documentation: |
| Pack arithmetic_types -- prolog/type_ndarray.pl |
This module implements arithmetic type (see module `arithmetic_types) ndarry, immutable, N-dimensional arrays largely patterned after Python's NumPy library. Support from slicing and indexing (0 based) are imported from module type_list. A one dimensional array is represented a compound term with functor # and arguments being the elements of the array. N-dimensional arrays are supported by allowing arrays as array elements. The elements of the array can be any Prolog term, although a subset of the defined arithmetic functions on ndarray's only succeed if the elements are numbers. (There is one exception described below.)
The only exported predicate is the type checking ndarray/1. Also exported are a set of array arithmetic operations: `.+, .-, .*,` etc.; refer ot source for a complete list. The set of arithmetic functions defined by this module include:
:- arithmetic_function(new/2). % new from shape, uninitialized
:- arithmetic_function(ndarray/1). % new from ListOfLists
:- arithmetic_function(to_list/1). % list from ndarray
:- arithmetic_function(ndim/1). % number of dimensions
:- arithmetic_function(shape/1). % shape (a list)
:- arithmetic_function(size/1). % number of values
:- arithmetic_function([]/1). % block indexing and slicing
:- arithmetic_function([]/2).
:- arithmetic_function(init/2). % initialize any variables
:- arithmetic_function(\\ /2). % row concat
:- arithmetic_function(flatten/1). % flattened array
:- arithmetic_function(reshape/2). % reshaped array
:- arithmetic_function(transpose/1). % transpose array
% numeric functions
:- arithmetic_function(arange/2). % new from range
:- arithmetic_function(arange/3). % new from range
:- arithmetic_function(arange/4). % new from range
:- arithmetic_function(identity/2). % new NxN identity matrix
:- arithmetic_function(sum/1). % sum of elements
:- arithmetic_function(min/1). % minimum of elements
:- arithmetic_function(max/1). % maximum of elements
:- arithmetic_function('.+'/2). % numeric array addition
:- arithmetic_function('.-'/1). % numeric array unary minus
:- arithmetic_function('.-'/2). % numeric array subtraction
:- arithmetic_function('.*'/2). % numeric array product
:- arithmetic_function('./'/2). % numeric array division
:- arithmetic_function('.**'/2). % numeric array power
:- arithmetic_function(apply/2). % apply function/1 to array
:- arithmetic_function(cross/2). % cross product of two 3D vectors
:- arithmetic_function(inner/2). % inner product of two vectors
:- arithmetic_function(outer/2). % outer product of two vectors
:- arithmetic_function('.@'/2). % dot product of two vectors/matrices
:- arithmetic_function(dot/2). % dot product of two vectors/matrices
:- arithmetic_function(determinant/1). % determinant of square matrix
:- arithmetic_function(inverse/1). % inverse of square matrix
type_ndarray supports the use of constrained numeric values as defined by library(clpBNR) If current_module(clpBNR) succeeds (i.e., the module has been loaded), instantiation errors from standard functional arithmetic will be interpreted as numeric constraints on the variable(s) in the sub-expression being evaluated. If clpBNR is not accessible, the original instantiation error will be propagated.
See the ReadMe for this pack for more documentation and examples.