MXNet/LinAlg.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 32 CC 1 SCAR 6.9
CC
1
Cov
0%
sym
2.0
symbol
2.0
nd
2.0
CRAP 2.0
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17  
18 package AI::MXNet::LinAlg;
19 use strict;
20 use warnings;
21 use AI::MXNet::NS;
22 use AI::MXNet::LinAlg::Symbol;
23 use AI::MXNet::LinAlg::NDArray;
24  
25 =head1 NAME
26  
27 AI::MXNet::LinAlg - Linear Algebra routines for NDArray and Symbol.
28 =cut
29  
30 =head1 DESCRIPTION
31  
32 The Linear Algebra API, provides imperative/symbolic linear algebra tensor operations on CPU/GPU.
33  
34 mx->linalg-><sym|nd>->gemm Performs general matrix multiplication and accumulation.
35 mx->linalg-><sym|nd>->gemm2 Performs general matrix multiplication.
36 mx->linalg-><sym|nd>->potrf Performs Cholesky factorization of a symmetric positive-definite matrix.
37 mx->linalg-><sym|nd>->potri Performs matrix inversion from a Cholesky factorization.
38 mx->linalg-><sym|nd>->trmm Performs multiplication with a lower triangular matrix.
39 mx->linalg-><sym|nd>->trsm Solves matrix equation involving a lower triangular matrix.
40 mx->linalg-><sym|nd>->sumlogdiag Computes the sum of the logarithms of the diagonal elements of a square matrix.
41 mx->linalg-><sym|nd>->syrk Multiplication of matrix with its transpose.
42 mx->linalg-><sym|nd>->gelqf LQ factorization for general matrix.
43 mx->linalg-><sym|nd>->syevd Eigendecomposition for symmetric matrix.
44 L<NDArray Python Docs|https://mxnet.apache.org/api/python/ndarray/linalg.html>
45 L<Symbol Python Docs|https://mxnet.apache.org/api/python/symbol/linalg.html>
46  
47 Examples:
48  
49 ## NDArray
50 my $A = mx->nd->array([[1.0, 1.0], [1.0, 1.0]]);
51 my $B = mx->nd->array([[1.0, 1.0], [1.0, 1.0], [1.0, 1.0]]);
52 ok(almost_equal(
53 mx->nd->linalg->gemm2($A, $B, transpose_b=>1, alpha=>2.0)->aspdl,
54 pdl([[4.0, 4.0, 4.0], [4.0, 4.0, 4.0]])
55 ));
56  
57 ## Symbol
58 my $sym_gemm2 = mx->sym->linalg->gemm2(
59 mx->sym->var('A'),
60 mx->sym->var('B'),
61 transpose_b => 1,
62 alpha => 2.0
63 );
64 my $A = mx->nd->array([[1.0, 1.0], [1.0, 1.0]]);
65 my $B = mx->nd->array([[1.0, 1.0], [1.0, 1.0], [1.0, 1.0]]);
66 ok(almost_equal(
67 $sym_gemm2->eval(args => { A => $A, B => $B })->[0]->aspdl,
68 pdl([[4.0, 4.0, 4.0], [4.0, 4.0, 4.0]])
69 ));
70  
71 =cut
72  
73 sub sym { 'AI::MXNet::LinAlg::Symbol' }
74 sub symbol { 'AI::MXNet::LinAlg::Symbol' }
75 sub nd { 'AI::MXNet::LinAlg::NDArray' }
76 sub ndarray { 'AI::MXNet::LinAlg::NDArray' }
77  
78 1;