LightJason - AgentSpeak(L++)
TestCActionMathBlasMatrix.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.action.builtin;
25 
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 cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D;
31 import com.codepoetics.protonpack.StreamUtils;
32 import com.tngtech.java.junit.dataprovider.DataProvider;
33 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
34 import com.tngtech.java.junit.dataprovider.UseDataProvider;
35 import org.apache.commons.lang3.tuple.ImmutableTriple;
36 import org.apache.commons.lang3.tuple.Triple;
37 import org.junit.Assert;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
80 
81 import java.lang.reflect.InvocationTargetException;
82 import java.util.ArrayList;
83 import java.util.Arrays;
84 import java.util.Collections;
85 import java.util.List;
86 import java.util.Random;
87 import java.util.stream.Collectors;
88 import java.util.stream.IntStream;
89 import java.util.stream.Stream;
90 
91 import static org.junit.Assert.assertTrue;
92 
96 @RunWith( DataProviderRunner.class )
97 public final class TestCActionMathBlasMatrix extends IBaseTest
98 {
99 
104  private static final DoubleMatrix2D MATRIX1 = new DenseDoubleMatrix2D( new double[][]{{2, 6}, {3, 8}} );
105 
110  private static final DoubleMatrix2D MATRIX2 = new DenseDoubleMatrix2D( new double[][]{{2, 2}, {3, 1}} );
111 
116  @DataProvider
117  public static Object[] generator()
118  {
119  return testcase(
120 
121  Stream.of( MATRIX1, MATRIX2 ),
122 
123  Stream.of(
124  CColumns.class,
125  CDimension.class,
126  CRows.class,
127  CNonZero.class,
128  CCondition.class,
129  CDeterminant.class,
130  CTwoNorm.class,
131  COneNorm.class,
132  CMatrixNorm.class,
133  CInfinityNorm.class,
134  CRank.class,
135  CSum.class,
136  CTrace.class
137  ),
138  Stream.of( 2D, 2D ),
139  Stream.of( 2D, 2D, 2D, 2D ),
140  Stream.of( 2D, 2D ),
141  Stream.of( 4D, 4D ),
142  Stream.of( 56.48229533707812, 4.265564437074639 ),
143  Stream.of( -2.000000000000001, -4.0 ),
144  Stream.of( 10.628480167651258, 4.130648586880582 ),
145  Stream.of( 14.0000, 5.0000 ),
146  Stream.of( 10.63014581273465, 4.242640687119285 ),
147  Stream.of( 11.0000, 4.0000 ),
148  Stream.of( 2D, 2D ),
149  Stream.of( MATRIX1.zSum(), MATRIX2.zSum() ),
150  Stream.of( 10.0, 3.0 )
151 
152  ).toArray();
153  }
154 
155 
164  @SafeVarargs
165  @SuppressWarnings( "varargs" )
166  private static Stream<Object> testcase( final Stream<Object> p_input, final Stream<Class<?>> p_classes, final Stream<Object>... p_classresult )
167  {
168  final List<ITerm> l_input = p_input.map( CRawTerm::from ).collect( Collectors.toList() );
169 
170  return StreamUtils.zip(
171  p_classes,
172  Arrays.stream( p_classresult ),
173  ( i, j ) -> new ImmutableTriple<>( l_input, i, j )
174  );
175  }
176 
177 
187  @Test
188  @UseDataProvider( "generator" )
189  public final void action( final Triple<List<ITerm>, Class<? extends IAction>, Stream<Object>> p_input )
190  throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
191  {
192  final List<ITerm> l_return = new ArrayList<>();
193 
194  p_input.getMiddle().getConstructor().newInstance().execute(
195  false, IContext.EMPTYPLAN,
196  p_input.getLeft(),
197  l_return
198  );
199 
200  Assert.assertArrayEquals(
201  p_input.getMiddle().toGenericString(),
202  l_return.stream().map( ITerm::raw ).toArray(),
203  p_input.getRight().toArray()
204  );
205  }
206 
210  @Test
211  public final void create()
212  {
213  final List<ITerm> l_return = new ArrayList<>();
214 
215  new CCreate().execute(
216  false,
218  Stream.of( 2, 2, "dense" ).map( CRawTerm::from ).collect( Collectors.toList() ),
219  l_return
220  );
221 
222  Assert.assertEquals( l_return.size(), 1 );
223  assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
224  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix2D>raw().size(), 4 );
225  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix2D>raw().rows(), 2 );
226  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix2D>raw().columns(), 2 );
227  }
228 
232  @Test
233  public final void column()
234  {
235  final List<ITerm> l_return = new ArrayList<>();
236 
237  new CColumn().execute(
238  false, IContext.EMPTYPLAN,
239  Stream.of( 1, MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
240  l_return
241  );
242 
243  Assert.assertEquals( l_return.size(), 1 );
244  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix1D );
245  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().size(), 2 );
246 
247  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().get( 0 ), 2, 0 );
248  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().get( 1 ), 1, 0 );
249  }
250 
254  @Test
255  public final void row()
256  {
257  final List<ITerm> l_return = new ArrayList<>();
258 
259  new CRow().execute(
260  false, IContext.EMPTYPLAN,
261  Stream.of( 1, MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
262  l_return
263  );
264 
265  Assert.assertEquals( l_return.size(), 1 );
266  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix1D );
267  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().size(), 2 );
268 
269  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().get( 0 ), 3, 0 );
270  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix1D>raw().get( 1 ), 1, 0 );
271  }
272 
276  @Test
277  public final void power()
278  {
279  final List<ITerm> l_return = new ArrayList<>();
280 
281  new CPower().execute(
282  false, IContext.EMPTYPLAN,
283  Stream.of( 2, MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
284  l_return
285  );
286 
287  Assert.assertEquals( l_return.size(), 1 );
288  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
289  Assert.assertEquals( l_return.get( 0 ).<DoubleMatrix2D>raw().size(), 4 );
290 
291  Assert.assertArrayEquals(
292  l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
293  new DenseDoubleMatrix2D( new double[][]{{10.0, 6.0}, {9.0, 7.0}} ).toArray()
294  );
295 
296  }
297 
301  @Test
302  public final void set()
303  {
304  new CSet().execute(
305  false, IContext.EMPTYPLAN,
306  Stream.of( 0, 1, 6.0, MATRIX1 ).map( CRawTerm::from ).collect( Collectors.toList() ),
307  Collections.emptyList()
308  );
309 
310  Assert.assertEquals( MATRIX1.get( 0, 1 ), 6, 0 );
311  }
312 
316  @Test
317  public final void tolist()
318  {
319  final List<ITerm> l_return = new ArrayList<>();
320 
321  new CToList().execute(
322  false, IContext.EMPTYPLAN,
323  Stream.of( MATRIX1 ).map( CRawTerm::from ).collect( Collectors.toList() ),
324  l_return
325  );
326 
327  Assert.assertEquals( l_return.size(), 1 );
328  Assert.assertTrue( l_return.get( 0 ).raw() instanceof List );
329 
330  Assert.assertArrayEquals(
331  l_return.get( 0 ).<List<?>>raw().toArray(),
332  Stream.of( 2.0, 6.0, 3.0, 8.0 ).collect( Collectors.toList() ).toArray()
333  );
334  }
335 
339  @Test
340  public final void transpose()
341  {
342  final List<ITerm> l_return = new ArrayList<>();
343 
344  new CTranspose().execute(
345  false, IContext.EMPTYPLAN,
346  Stream.of( MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
347  l_return
348  );
349 
350  Assert.assertEquals( l_return.size(), 1 );
351  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
352 
353  Assert.assertArrayEquals(
354  l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
355  new DenseDoubleMatrix2D( new double[][]{{2.0, 3.0}, {2.0, 1.0}} ).toArray()
356  );
357  }
358 
362  @Test
363  public final void submatrix()
364  {
365  final List<ITerm> l_return = new ArrayList<>();
366 
367  new CSubMatrix().execute(
368  false, IContext.EMPTYPLAN,
369  Stream.of( 0, 0, 0, 1, MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
370  l_return
371  );
372 
373  Assert.assertEquals( l_return.size(), 1 );
374  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
375 
376  Assert.assertArrayEquals(
377  l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
378  new DenseDoubleMatrix2D( new double[][]{{2.0, 2.0}} ).toArray()
379  );
380  }
381 
385  @Test
386  public final void solve()
387  {
388  final List<ITerm> l_return = new ArrayList<>();
389 
390  new CSolve().execute(
391  false, IContext.EMPTYPLAN,
392  Stream.of( MATRIX1, MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
393  l_return
394  );
395 
396  Assert.assertEquals( l_return.size(), 1 );
397  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
398 
399  Assert.assertArrayEquals(
400  l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
401  new DenseDoubleMatrix2D( new double[][]{{1.0, -4.999999999999998}, {0.0, 1.9999999999999993}} ).toArray()
402  );
403  }
404 
408  @Test
409  public final void assignscalar()
410  {
411  final DoubleMatrix2D l_matrix = new DenseDoubleMatrix2D( 2, 2 );
412 
413  new CAssign().execute(
414  false, IContext.EMPTYPLAN,
415  Stream.of( 2, l_matrix ).map( CRawTerm::from ).collect( Collectors.toList() ),
416  Collections.emptyList()
417  );
418 
419  Assert.assertArrayEquals( l_matrix.toArray(), new double[][]{{2.0, 2.0}, {2.0, 2.0}} );
420  }
421 
425  @Test
426  public final void assignmatrix()
427  {
428  final DoubleMatrix2D l_matrix = new DenseDoubleMatrix2D( 2, 2 );
429 
430  new CAssign().execute(
431  false, IContext.EMPTYPLAN,
432  Stream.of( MATRIX2, l_matrix ).map( CRawTerm::from ).collect( Collectors.toList() ),
433  Collections.emptyList()
434  );
435 
436  Assert.assertArrayEquals( MATRIX2.toArray(), l_matrix.toArray() );
437  }
438 
442  @Test
443  public final void get()
444  {
445  final List<ITerm> l_return = new ArrayList<>();
446 
447  new CGet().execute(
448  false, IContext.EMPTYPLAN,
449  Stream.of( MATRIX2, 0, 1 ).map( CRawTerm::from ).collect( Collectors.toList() ),
450  l_return
451  );
452 
453  Assert.assertEquals( l_return.size(), 1 );
454  Assert.assertTrue( l_return.get( 0 ).raw() instanceof Double );
455  Assert.assertEquals( l_return.get( 0 ).<Double>raw(), 2, 0 );
456  }
457 
461  @Test
462  public final void parse()
463  {
464  final List<ITerm> l_return = new ArrayList<>();
465 
466  new CParse().execute(
467  false, IContext.EMPTYPLAN,
468  Stream.of( "1,2;3,4", "dense" ).map( CRawTerm::from ).collect( Collectors.toList() ),
469  l_return
470  );
471 
472  Assert.assertEquals( l_return.size(), 1 );
473  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
474  Assert.assertArrayEquals(
475  l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
476  new DenseDoubleMatrix2D( new double[][]{{1.0, 2.0}, {3.0, 4.0}} ).toArray()
477  );
478  }
479 
483  @Test
484  public final void invert()
485  {
486  final List<ITerm> l_return = new ArrayList<>();
487 
488  new CInvert().execute(
489  false, IContext.EMPTYPLAN,
490  Stream.of( MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
491  l_return
492  );
493 
494  Assert.assertEquals( l_return.size(), 1 );
495  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DoubleMatrix2D );
496  Assert.assertArrayEquals(
497  l_return.get( 0 ).<DoubleMatrix2D>raw().toArray(),
498  new DenseDoubleMatrix2D( new double[][]{{-0.24999999999999994, 0.5}, {0.7499999999999999, -0.4999999999999999}} ).toArray()
499  );
500  }
501 
505  @Test
506  public final void eigen()
507  {
508  final List<ITerm> l_return = new ArrayList<>();
509 
510  new CEigen().execute(
511  false, IContext.EMPTYPLAN,
512  Stream.of( MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
513  l_return
514  );
515 
516  Assert.assertEquals( l_return.size(), 2 );
517  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DenseDoubleMatrix1D );
518  Assert.assertArrayEquals( l_return.get( 0 ).<DenseDoubleMatrix1D>raw().toArray(), Stream.of( 4, -1 ).mapToDouble( i -> i ).toArray(), 0 );
519 
520  Assert.assertTrue( l_return.get( 1 ).raw() instanceof DoubleMatrix2D );
521  Assert.assertArrayEquals(
522  l_return.get( 1 ).<DoubleMatrix2D>raw().toArray(),
523  new DenseDoubleMatrix2D( new double[][]{{0.7071067811865475, -0.565685424949238}, {0.7071067811865475, 0.8485281374238569}} ).toArray()
524  );
525  }
526 
530  @Test
531  public final void singularvalue()
532  {
533  final List<ITerm> l_return = new ArrayList<>();
534 
535  new CSingularValue().execute(
536  false, IContext.EMPTYPLAN,
537  Stream.of( MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
538  l_return
539  );
540 
541  Assert.assertEquals( l_return.size(), 3 );
542  Assert.assertTrue( l_return.get( 0 ).raw() instanceof DenseDoubleMatrix1D );
543  Assert.assertArrayEquals( l_return.get( 0 ).<DenseDoubleMatrix1D>raw().toArray(),
544  Stream.of( 4.130648586880582, 0.9683709267122025 ).mapToDouble( i -> i ).toArray(), 0 );
545 
546  Assert.assertTrue( l_return.get( 1 ).raw() instanceof DoubleMatrix2D );
547  Assert.assertArrayEquals(
548  l_return.get( 1 ).<DoubleMatrix2D>raw().toArray(),
549  new DenseDoubleMatrix2D( new double[][]{{-0.6618025632357403, -0.7496781758158657}, {-0.7496781758158659, 0.66180256323574}} ).toArray()
550  );
551 
552  Assert.assertTrue( l_return.get( 2 ).raw() instanceof DoubleMatrix2D );
553  Assert.assertArrayEquals(
554  l_return.get( 2 ).<DoubleMatrix2D>raw().toArray(),
555  new DenseDoubleMatrix2D( new double[][]{{-0.8649100931185951, 0.5019268181932333}, {-0.5019268181932333, -0.8649100931185951}} ).toArray()
556  );
557  }
558 
562  @Test
563  public final void copy()
564  {
565  final List<ITerm> l_return = new ArrayList<>();
566 
567  new CCopy().execute(
568  false, IContext.EMPTYPLAN,
569  Stream.of( MATRIX1, MATRIX2 ).map( CRawTerm::from ).collect( Collectors.toList() ),
570  l_return
571  );
572 
573  Assert.assertEquals( l_return.size(), 2 );
574  Assert.assertArrayEquals( l_return.stream().map( ITerm::raw ).toArray(), Stream.of( MATRIX1, MATRIX2 ).toArray() );
575  }
576 
577 
581  @Test
582  public final void graphlaplacian()
583  {
584  final List<ITerm> l_return = new ArrayList<>();
585 
586  new CGraphLaplacian().execute(
587  false, IContext.EMPTYPLAN,
588  Stream.of(
589  new SparseDoubleMatrix2D( new double[][]{
590  {0, 1, 0, 0, 1, 0},
591  {1, 0, 1, 0, 1, 0},
592  {0, 1, 0, 1, 0, 0},
593  {0, 0, 1, 0, 1, 1},
594  {1, 1, 0, 1, 0, 0},
595  {0, 0, 0, 1, 0, 0}
596  } )
597  ).map( CRawTerm::from ).collect( Collectors.toList() ),
598  l_return
599  );
600 
601  Assert.assertEquals( l_return.size(), 1 );
602  final DoubleMatrix2D l_result = l_return.get( 0 ).raw();
603 
604  IntStream.range( 0, l_result.rows() )
605  .boxed()
606  .map( l_result::viewRow )
607  .mapToDouble( DoubleMatrix1D::zSum )
608  .forEach( i -> Assert.assertEquals( i, 0, 0 ) );
609 
610  IntStream.range( 0, l_result.columns() )
611  .boxed()
612  .map( l_result::viewColumn )
613  .mapToDouble( DoubleMatrix1D::zSum )
614  .forEach( i -> Assert.assertEquals( i, 0, 0 ) );
615  }
616 
617 
621  @Test
622  public final void normalizedgraphlaplacian()
623  {
624  final List<ITerm> l_return = new ArrayList<>();
625 
627  false, IContext.EMPTYPLAN,
628  Stream.of(
629  new SparseDoubleMatrix2D( new double[][]{
630  {0, 1, 0, 0, 1, 0},
631  {1, 0, 1, 0, 1, 0},
632  {0, 1, 0, 1, 0, 0},
633  {0, 0, 1, 0, 1, 1},
634  {1, 1, 0, 1, 0, 0},
635  {0, 0, 0, 1, 0, 0}
636  } )
637  ).map( CRawTerm::from ).collect( Collectors.toList() ),
638  l_return
639  );
640 
641  Assert.assertEquals( l_return.size(), 1 );
642  final DoubleMatrix2D l_result = l_return.get( 0 ).raw();
643 
644  IntStream.range( 0, l_result.rows() ).boxed().forEach( i -> Assert.assertEquals( l_result.getQuick( i, i ), 1, 0 ) );
645  IntStream.range( 0, l_result.rows() )
646  .boxed()
647  .map( l_result::viewRow )
648  .mapToDouble( DoubleMatrix1D::zSum )
649  .forEach( i -> Assert.assertEquals( i, 0, 1e-10 ) );
650  }
651 
655  @Test
656  public final void rowsum()
657  {
658  final List<ITerm> l_return = new ArrayList<>();
659 
660  new CRowSum().execute(
661  false, IContext.EMPTYPLAN,
662  Stream.of(
663  new SparseDoubleMatrix2D( new double[][]{
664  {1, 0, 0, 0, 0, 0},
665  {1, 2, 0, 0, 0, 0},
666  {1, 2, 3, 0, 0, 0},
667  {1, 2, 3, 4, 0, 0},
668  {1, 2, 3, 4, 5, 0},
669  {1, 2, 3, -1, -2, -3}
670  } )
671  ).map( CRawTerm::from ).collect( Collectors.toList() ),
672  l_return
673  );
674 
675  Assert.assertEquals( l_return.size(), 1 );
676  Assert.assertArrayEquals(
677  Arrays.stream( l_return.get( 0 ).<DoubleMatrix1D>raw().toArray() ).boxed().toArray(),
678  Stream.of( 1D, 3D, 6D, 10D, 15D, 0D ).toArray()
679  );
680  }
681 
682 
686  @Test
687  public final void columsum()
688  {
689  final List<ITerm> l_return = new ArrayList<>();
690 
691  new CColumnSum().execute(
692  false, IContext.EMPTYPLAN,
693  Stream.of(
694  new SparseDoubleMatrix2D( new double[][]{
695  {1, 0, 0, 0, 0, 0},
696  {1, 2, 0, 0, 0, 0},
697  {1, 2, 3, 0, 0, 0},
698  {1, 2, 3, 4, 0, 0},
699  {1, 2, 3, 4, 5, 0},
700  {1, 2, 3, -1, -2, -3}
701  } )
702  ).map( CRawTerm::from ).collect( Collectors.toList() ),
703  l_return
704  );
705 
706  Assert.assertEquals( l_return.size(), 1 );
707  Assert.assertArrayEquals(
708  Arrays.stream( l_return.get( 0 ).<DoubleMatrix1D>raw().toArray() ).boxed().toArray(),
709  Stream.of( 6D, 10D, 12D, 7D, 3D, -3D ).toArray()
710  );
711  }
712 
713 
717  @Test
718  public final void identity()
719  {
720  final int l_size = Math.abs( new Random().nextInt( 98 ) + 2 );
721  final List<ITerm> l_return = new ArrayList<>();
722 
723  new CIdentity().execute(
724  false, IContext.EMPTYPLAN,
725  Stream.of( l_size ).map( CRawTerm::from ).collect( Collectors.toList() ),
726  l_return
727  );
728 
729  Assert.assertEquals( l_return.size(), 1 );
730  final DoubleMatrix2D l_result = l_return.get( 0 ).raw();
731 
732  Assert.assertTrue(
733  IntStream.range( 0, l_result.rows() )
734  .boxed()
735  .flatMap( i -> IntStream.range( 0, l_result.columns() )
736  .boxed()
737  .map( j -> i.equals( j ) ? l_result.getQuick( i, j ) == 1D : l_result.getQuick( i, j ) == 0D )
738  )
739  .allMatch( i -> i )
740  );
741  }
742 
743 
747  @Test
748  public final void diagonal()
749  {
750  final List<ITerm> l_return = new ArrayList<>();
751  final double[] l_data = new double[]{1, 3, 5, 11};
752 
753  new CDiagonal().execute(
754  false, IContext.EMPTYPLAN,
755  Stream.of(
756  new DenseDoubleMatrix1D( l_data )
757  ).map( CRawTerm::from ).collect( Collectors.toList() ),
758  l_return
759  );
760 
761  Assert.assertEquals( l_return.size(), 1 );
762  final DoubleMatrix2D l_result = l_return.get( 0 ).raw();
763 
764  Assert.assertArrayEquals(
765  Arrays.stream( l_data ).boxed().toArray(),
766  IntStream.range( 0, l_result.rows() )
767  .boxed()
768  .map( i -> l_result.getQuick( i, i ) )
769  .toArray()
770  );
771 
772  IntStream.range( 0, l_result.rows() )
773  .forEach( i -> IntStream.range( 0, l_result.columns() )
774  .filter( j -> i != j )
775  .forEach( j -> Assert.assertEquals( l_result.getQuick( i, j ), 0, 0 ) ) );
776  }
777 
778 }
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 frobenius- / matrix-norm of a 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
Definition: IRowColumn.java:70
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
Definition: CInvert.java:72
base test class with helpers
Definition: IBaseTest.java:33
creates a dense- or sparse-matrix from a string.
IContext EMPTYPLAN
empty context with plan
Definition: IContext.java:47
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
Definition: CRowSum.java:72
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
creates the real eigenvalues and eigenvectors of a matrix.
Definition: CEigen.java:50
execution context with local data
Definition: IContext.java:42
external action interface
Definition: IAction.java:38
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
Definition: CDiagonal.java:72
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
Definition: CTranspose.java:72
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
Definition: CColumnSum.java:72
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
Definition: CIdentity.java:71
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
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
Definition: CEigen.java:74
< T > T raw()
cast to any raw value type
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
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
Definition: CRawTerm.java:104
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
Definition: CSubMatrix.java:73
creates the singular value decomposition of a 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 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
term structure for simple datatypes
Definition: CRawTerm.java:45
returns the dimension (rows / columns) of a bit matrix.