1
// Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
2
// Copyright (C) 2010-2011 Conrad Sanderson
1
// Copyright (C) 2010-2013 NICTA (www.nicta.com.au)
2
// Copyright (C) 2010-2013 Conrad Sanderson
4
4
// This Source Code Form is subject to the terms of the Mozilla Public
5
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
20
20
arma_extra_debug_sigprint();
22
typedef typename T1::elem_type eT;
23
typedef typename Proxy<T1>::ea_type ea_type1;
24
typedef typename Proxy<T2>::ea_type ea_type2;
26
const Proxy<T1> A(X.A);
27
const Proxy<T2> B(X.B);
29
arma_debug_check( ((A.get_n_elem() != 3) || (B.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" );
31
out.set_size(A.get_n_rows(), A.get_n_cols());
33
eT* out_mem = out.memptr();
34
ea_type1 PA = A.get_ea();
35
ea_type2 PB = B.get_ea();
45
out_mem[0] = ay*bz - az*by;
46
out_mem[1] = az*bx - ax*bz;
47
out_mem[2] = ax*by - ay*bx;
22
typedef typename T1::elem_type eT;
24
const Proxy<T1> PA(X.A);
25
const Proxy<T2> PB(X.B);
27
arma_debug_check( ((PA.get_n_elem() != 3) || (PB.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" );
29
const uword PA_n_rows = Proxy<T1>::is_row ? 1 : PA.get_n_rows();
30
const uword PA_n_cols = Proxy<T1>::is_col ? 1 : PA.get_n_cols();
32
out.set_size(PA_n_rows, PA_n_cols);
34
eT* out_mem = out.memptr();
36
if( (Proxy<T1>::prefer_at_accessor == false) && (Proxy<T2>::prefer_at_accessor == false) )
38
typename Proxy<T1>::ea_type A = PA.get_ea();
39
typename Proxy<T2>::ea_type B = PB.get_ea();
49
out_mem[0] = ay*bz - az*by;
50
out_mem[1] = az*bx - ax*bz;
51
out_mem[2] = ax*by - ay*bx;
55
const bool PA_is_col = Proxy<T1>::is_col ? true : (PA_n_cols == 1);
56
const bool PB_is_col = Proxy<T2>::is_col ? true : (PB.get_n_cols() == 1);
58
const eT ax = PA.at(0,0);
59
const eT ay = PA_is_col ? PA.at(1,0) : PA.at(0,1);
60
const eT az = PA_is_col ? PA.at(2,0) : PA.at(0,2);
62
const eT bx = PB.at(0,0);
63
const eT by = PB_is_col ? PB.at(1,0) : PB.at(0,1);
64
const eT bz = PB_is_col ? PB.at(2,0) : PB.at(0,2);
66
out_mem[0] = ay*bz - az*by;
67
out_mem[1] = az*bx - ax*bz;
68
out_mem[2] = ax*by - ay*bx;