ReFRACtor
fp_gsl_matrix.cc
Go to the documentation of this file.
1 #include "fp_gsl_matrix.h"
2 #include "linear_algebra.h"
3 #include <cstdlib>
4 
5 using namespace FullPhysics;
6 
7 //-----------------------------------------------------------------------
12 //-----------------------------------------------------------------------
13 
14 void GslMatrix::reset(gsl_matrix* M, bool Owned)
15 {
17  free(gsl_matrix_->block);
18  if(gsl_matrix_ && owned_)
19  gsl_matrix_free(gsl_matrix_);
20  gsl_matrix_ = M;
21  blitz::Array<double, 2> a(M->data, blitz::shape(M->size1, M->size2),
22  blitz::shape(M->tda, 1), blitz::neverDeleteData);
23  blitz_array_.reference(a);
24  owned_ = Owned;
25  block_owned_ = false;
26 }
27 
28 //-----------------------------------------------------------------------
37 //-----------------------------------------------------------------------
38 
39 void GslMatrix::reset(blitz::Array<double, 2>& M)
40 {
42  free(gsl_matrix_->block);
43  if(gsl_matrix_ && owned_)
44  gsl_matrix_free(gsl_matrix_);
45  blitz_array_.reference(to_c_order(M));
46  gsl_matrix_ = (gsl_matrix*) malloc(sizeof(gsl_matrix));
47  gsl_matrix_->size1 = blitz_array_.rows();
48  gsl_matrix_->size2 = blitz_array_.cols();
49  gsl_matrix_->tda = blitz_array_.cols();
50  gsl_matrix_->data = blitz_array_.data();
51  gsl_matrix_->owner = 0;
52  gsl_matrix_->block = (gsl_block*) malloc(sizeof(gsl_block));
53  gsl_matrix_->block->size = blitz_array_.size();
54  gsl_matrix_->block->data = blitz_array_.data();
55  owned_ = true;
56  block_owned_ = true;
57 }
58 
59 //-----------------------------------------------------------------------
61 //-----------------------------------------------------------------------
62 
64 {
66  free(gsl_matrix_->block);
67  if(gsl_matrix_ && owned_)
68  gsl_matrix_free(gsl_matrix_);
69 }
70 
71 //-----------------------------------------------------------------------
76 //-----------------------------------------------------------------------
77 
78 void GslVector::reset(gsl_vector* M, bool Owned)
79 {
80  if(gsl_vector_ && block_owned_)
81  free(gsl_vector_->block);
82  if(gsl_vector_ && owned_)
83  gsl_vector_free(gsl_vector_);
84  gsl_vector_ = M;
85  blitz::Array<double, 1> a(M->data, blitz::shape(M->size),
86  blitz::shape(M->stride), blitz::neverDeleteData);
87  blitz_array_.reference(a);
88  owned_ = Owned;
89  block_owned_ = false;
90 }
91 
92 //-----------------------------------------------------------------------
100 //-----------------------------------------------------------------------
101 
102 void GslVector::reset(blitz::Array<double, 1>& M)
103 {
104  if(gsl_vector_ && block_owned_)
105  free(gsl_vector_->block);
106  if(gsl_vector_ && owned_)
107  gsl_vector_free(gsl_vector_);
108  blitz_array_.reference(to_c_order(M));
109  gsl_vector_ = (gsl_vector*) malloc(sizeof(gsl_vector));
110  gsl_vector_->size = blitz_array_.rows();
111  gsl_vector_->stride = 1;
112  gsl_vector_->data = blitz_array_.data();
113  gsl_vector_->owner = 0;
114  gsl_vector_->block = (gsl_block*) malloc(sizeof(gsl_block));
115  gsl_vector_->block->size = blitz_array_.size();
116  gsl_vector_->block->data = blitz_array_.data();
117  owned_ = true;
118  block_owned_ = true;
119 }
120 
121 //-----------------------------------------------------------------------
123 //-----------------------------------------------------------------------
124 
126 {
127  if(gsl_vector_ && block_owned_)
128  free(gsl_vector_->block);
129  if(gsl_vector_ && owned_)
130  gsl_vector_free(gsl_vector_);
131 }
132 
void reset(gsl_vector *M, bool Owned=true)
Reset class to point to new vector.
~GslVector()
Destructor.
gsl_matrix * gsl_matrix_
Definition: fp_gsl_matrix.h:79
~GslMatrix()
Destructor.
blitz::Array< double, 2 > blitz_array_
Definition: fp_gsl_matrix.h:78
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
void reset(gsl_matrix *M, bool Owned=true)
Reset class to point to new matrix.
blitz::Array< T, D > to_c_order(const blitz::Array< T, D > &In)
Ensure that a given blitz::Array is contiguous, not reversed, and in C RowMajorArray format...

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11