Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Functions/builtin/cross.cs @ 9102

Last change on this file since 9102 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 5.6 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Text;
43using System.Runtime.InteropServices;
44using ILNumerics.Storage;
45using ILNumerics.Misc;
46using ILNumerics.Native;
47using ILNumerics.Exceptions;
48
49
50namespace ILNumerics {
51
52    public partial class ILMath {
53
54
55        /// <summary>
56        /// Cross products of columns of two arrays
57        /// </summary>
58        /// <param name="A">First array with vectors in columns</param>
59        /// <param name="B">Second array with vectors in columns</param>
60        /// <returns>Array with cross products of vectors from A and B</returns>
61        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">If the size of both arguments is not the same.</exception>
62        public static ILRetArray<double> cross(ILInArray<double> A,
63                                                            ILInArray<double> B,
64                                                            bool normalize = false) {
65            using (ILScope.Enter(A, B)) {
66                if (!A.Size.IsSameSize(B.Size))
67                    throw new ILArgumentException("input arrays must have the same size!");
68                ILArray<double> ret = array<double>(A.Size);
69                using (ILScope.Enter()) {
70                    ILArray<double> Ax = A[0, full];
71                    ILArray<double> Ay = A[1, full];
72                    ILArray<double> Az = A[2, full];
73                    ILArray<double> Bx = B[0, full];
74                    ILArray<double> By = B[1, full];
75                    ILArray<double> Bz = B[2, full];
76                    ret[0, full] = Ay * Bz - Az * By;
77                    ret[1, full] = Az * Bx - Ax * Bz;
78                    ret[2, full] = Ax * By - Ay * Bx;
79                }
80                if (!normalize)
81                    return ret;
82                else
83                    return ret / sqrt(sum(ret * ret,0));
84            }
85        }
86
87#region HYCALPER AUTO GENERATED CODE
88
89        /// <summary>
90        /// Cross products of columns of two arrays
91        /// </summary>
92        /// <param name="A">First array with vectors in columns</param>
93        /// <param name="B">Second array with vectors in columns</param>
94        /// <returns>Array with cross products of vectors from A and B</returns>
95        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">If the size of both arguments is not the same.</exception>
96        public static ILRetArray<float> cross(ILInArray<float> A,
97                                                            ILInArray<float> B,
98                                                            bool normalize = false) {
99            using (ILScope.Enter(A, B)) {
100                if (!A.Size.IsSameSize(B.Size))
101                    throw new ILArgumentException("input arrays must have the same size!");
102                ILArray<float> ret = array<float>(A.Size);
103                using (ILScope.Enter()) {
104                    ILArray<float> Ax = A[0, full];
105                    ILArray<float> Ay = A[1, full];
106                    ILArray<float> Az = A[2, full];
107                    ILArray<float> Bx = B[0, full];
108                    ILArray<float> By = B[1, full];
109                    ILArray<float> Bz = B[2, full];
110                    ret[0, full] = Ay * Bz - Az * By;
111                    ret[1, full] = Az * Bx - Ax * Bz;
112                    ret[2, full] = Ax * By - Ay * Bx;
113                }
114                if (!normalize)
115                    return ret;
116                else
117                    return ret / sqrt(sum(ret * ret,0));
118            }
119        }
120
121#endregion HYCALPER AUTO GENERATED CODE
122
123    }
124}
Note: See TracBrowser for help on using the repository browser.