24 package org.lightjason.agentspeak.action.builtin;
26 import cern.colt.matrix.tdouble.DoubleMatrix1D;
27 import cern.colt.matrix.tdouble.DoubleMatrix2D;
28 import cern.colt.matrix.tdouble.impl.DenseDoubleMatrix1D;
29 import cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
41 import java.util.ArrayList;
42 import java.util.List;
43 import java.util.stream.Collectors;
44 import java.util.stream.Stream;
73 m_matrix1 =
new DenseDoubleMatrix2D(
new double[][]{{2, 6}, {3, 8}} );
74 m_matrix2 =
new DenseDoubleMatrix2D(
new double[][]{{2, 2}, {3, 1}} );
75 m_vector =
new DenseDoubleMatrix1D(
new double[]{2, 5} );
84 final List<ITerm> l_return =
new ArrayList<>();
88 Stream.of( m_matrix1 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
92 Assert.assertEquals( l_return.size(), 1 );
93 Assert.assertEquals( l_return.get( 0 ).<Number>raw(), 4D );
102 final List<ITerm> l_return =
new ArrayList<>();
106 Stream.of( m_matrix1, m_matrix2, m_matrix1, m_vector, m_vector, m_vector, m_vector, m_matrix2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
110 Assert.assertEquals( l_return.size(), 4 );
111 Assert.assertArrayEquals( l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{22.0, 10.0}, {30.0, 14.0}} );
112 Assert.assertArrayEquals( l_return.get( 1 ).<DoubleMatrix1D>raw().toArray(),
new double[]{34.0, 46.0}, 0 );
113 Assert.assertArrayEquals( l_return.get( 2 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{4.0, 10.0}, {10.0, 25.0}} );
114 Assert.assertArrayEquals( l_return.get( 3 ).<DoubleMatrix1D>raw().toArray(),
new double[]{14.0, 11.0}, 0 );
123 final List<ITerm> l_return =
new ArrayList<>();
128 m_matrix1,
"+", m_matrix2,
133 m_matrix1,
"|+|", m_matrix2,
134 m_matrix1,
"-", m_matrix2,
135 m_matrix1,
"*", m_matrix2,
141 Assert.assertEquals( l_return.size(), 9 );
142 Assert.assertArrayEquals( l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{4.0, 8.0}, {6.0, 9.0}} );
143 Assert.assertArrayEquals( l_return.get( 1 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{7.0, 11.0}, {8.0, 13.0}} );
144 Assert.assertArrayEquals( l_return.get( 2 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{-3.0, 1.0}, {-2.0, 3.0}} );
145 Assert.assertArrayEquals( l_return.get( 3 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{10.0, 30.0}, {15.0, 40.0}} );
146 Assert.assertArrayEquals( l_return.get( 4 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{1.0, 3.0}, {1.5, 4.0}} );
147 Assert.assertArrayEquals( l_return.get( 5 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{4.0, 8.0}, {6.0, 9.0}} );
148 Assert.assertArrayEquals( l_return.get( 6 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{0.0, 4.0}, {0.0, 7.0}} );
149 Assert.assertArrayEquals( l_return.get( 7 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{4.0, 12.0}, {9.0, 8.0}} );
150 Assert.assertArrayEquals( l_return.get( 8 ).<DoubleMatrix2D>raw().toArray(),
new double[][]{{7.0, 3.0}, {6.0, 1.0}} );
160 final List<ITerm> l_return =
new ArrayList<>();
165 m_vector,
"+", m_vector,
170 m_vector,
"-", m_vector,
171 m_vector,
"*", m_vector,
177 Assert.assertEquals( l_return.size(), 8 );
178 Assert.assertArrayEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().toArray(),
new double[]{4.0, 10.0}, 0 );
179 Assert.assertArrayEquals( l_return.get( 1 ).<DoubleMatrix1D>raw().toArray(),
new double[]{7.0, 10.0}, 0 );
180 Assert.assertArrayEquals( l_return.get( 2 ).<DoubleMatrix1D>raw().toArray(),
new double[]{-3.0, 0.0}, 0 );
181 Assert.assertArrayEquals( l_return.get( 3 ).<DoubleMatrix1D>raw().toArray(),
new double[]{10.0, 25.0}, 0 );
182 Assert.assertArrayEquals( l_return.get( 4 ).<DoubleMatrix1D>raw().toArray(),
new double[]{1.0, 2.5}, 0 );
183 Assert.assertArrayEquals( l_return.get( 5 ).<DoubleMatrix1D>raw().toArray(),
new double[]{0.0, 0.0}, 0 );
184 Assert.assertArrayEquals( l_return.get( 6 ).<DoubleMatrix1D>raw().toArray(),
new double[]{4.0, 25.0}, 0 );
185 Assert.assertArrayEquals( l_return.get( 7 ).<DoubleMatrix1D>raw().toArray(),
new double[]{3.0, 0.0}, 0 );
final void size()
test size
base test class with helpers
final void multiply()
test multiply
IContext EMPTYPLAN
empty context with plan
DoubleMatrix2D m_matrix1
testing matrix
final void initialize()
test initialize
returns the elements within the BLAS structure.
final void elementwisematrix()
test elementwise for matrix
execution context with local data
DoubleMatrix2D m_matrix2
testing matrix
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void elementwisevector()
test elementwise for vector
elementweise vector / matrix operation.
DoubleMatrix1D m_vector
testing vector
defines matrix- / vector-products.
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
returns the size of the collection.
term structure for simple datatypes