~ubuntu-branches/ubuntu/trusty/r-cran-rcpparmadillo/trusty-proposed

« back to all changes in this revision

Viewing changes to inst/include/armadillo_bits/glue_cross_meat.hpp

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2013-07-31 16:40:01 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130731164001-h9t7espn2nh9wf9p
Tags: 0.3.900.7-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
3
3
// 
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
19
19
  {
20
20
  arma_extra_debug_sigprint();
21
21
  
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;
25
 
  
26
 
  const Proxy<T1> A(X.A);
27
 
  const Proxy<T2> B(X.B);
28
 
  
29
 
  arma_debug_check( ((A.get_n_elem() != 3) || (B.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" );
30
 
  
31
 
  out.set_size(A.get_n_rows(), A.get_n_cols());
32
 
  
33
 
  eT*      out_mem = out.memptr();
34
 
  ea_type1 PA      = A.get_ea();
35
 
  ea_type2 PB      = B.get_ea();
36
 
  
37
 
  const eT ax = PA[0];
38
 
  const eT ay = PA[1];
39
 
  const eT az = PA[2];
40
 
  
41
 
  const eT bx = PB[0];
42
 
  const eT by = PB[1];
43
 
  const eT bz = PB[2];
44
 
  
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;
 
23
  
 
24
  const Proxy<T1> PA(X.A);
 
25
  const Proxy<T2> PB(X.B);
 
26
  
 
27
  arma_debug_check( ((PA.get_n_elem() != 3) || (PB.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" );
 
28
  
 
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();
 
31
  
 
32
  out.set_size(PA_n_rows, PA_n_cols);
 
33
  
 
34
  eT* out_mem = out.memptr();
 
35
  
 
36
  if( (Proxy<T1>::prefer_at_accessor == false) && (Proxy<T2>::prefer_at_accessor == false) )
 
37
    {
 
38
    typename Proxy<T1>::ea_type A = PA.get_ea();
 
39
    typename Proxy<T2>::ea_type B = PB.get_ea();
 
40
    
 
41
    const eT ax = A[0];
 
42
    const eT ay = A[1];
 
43
    const eT az = A[2];
 
44
    
 
45
    const eT bx = B[0];
 
46
    const eT by = B[1];
 
47
    const eT bz = B[2];
 
48
    
 
49
    out_mem[0] = ay*bz - az*by;
 
50
    out_mem[1] = az*bx - ax*bz;
 
51
    out_mem[2] = ax*by - ay*bx;
 
52
    }
 
53
  else
 
54
    {
 
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);
 
57
    
 
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);
 
61
    
 
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);
 
65
    
 
66
    out_mem[0] = ay*bz - az*by;
 
67
    out_mem[1] = az*bx - ax*bz;
 
68
    out_mem[2] = ax*by - ay*bx;
 
69
    }
48
70
  }
49
71
 
50
72