99 typedef struct {
I*
a;
S j;
C mflag,unused;}
MS;
114 inline static int fromB01(
bool& v,
const B d) {v=(d!=0);
return 0;};
115 inline static int fromLIT(
bool& v,
const C d) {
return ERR_CONV;};
116 inline static int fromINT(
bool& v,
const I d) {
return ERR_CONV;};
117 inline static int fromFL(
bool& v,
const D d) {
return ERR_CONV;};
118 inline static int fromCMPX(
bool& v,
const Z d) {
return ERR_CONV;};
119 inline static int toB01(
const bool v,
B& d) {d=v;
return 0;};
120 inline static int toLIT(
const bool v,
C& d) {
return ERR_CONV;};
121 inline static int toINT(
const bool v,
I& d) {d=v;
return 0;};
122 inline static int toFL(
const bool v,
D& d) {d=v;
return 0;};
123 inline static int toCMPX(
const bool v, Z& d) {d.re=v; d.im=0;
return 0;};
128 inline static int fromB01(
char& v,
const B d) {
return ERR_CONV;};
129 inline static int fromLIT(
char& v,
const C d) {v=d;
return 0;};
130 inline static int fromINT(
char& v,
const I d) {
return ERR_CONV;};
131 inline static int fromFL(
char& v,
const D d) {
return ERR_CONV;};
132 inline static int fromCMPX(
char& v,
const Z d) {
return ERR_CONV;};
133 inline static int toB01(
const char v,
B& d) {
return ERR_CONV;};
134 inline static int toLIT(
const char v,
C& d) {d=v;
return 0;};
135 inline static int toINT(
const char v,
I& d) {d=v;
return 0;};
136 inline static int toFL(
const char v,
D& d) {d=v;
return 0;};
137 inline static int toCMPX(
const char v, Z& d) {d.re=v; d.im=0;
return 0;};
140 inline static int fromB01(
int& v,
const B d) {v=d;
return 0;};
141 inline static int fromLIT(
int& v,
const C d) {v=d;
return 0;};
142 inline static int fromINT(
int& v,
const I d) {v=d;
return 0;};
143 inline static int fromFL(
int& v,
const D d) {
return ERR_CONV;};
144 inline static int fromCMPX(
int& v,
const Z d) {
return ERR_CONV;};
145 inline static int toB01(
const int v,
B& d) {
return ERR_CONV;};
146 inline static int toLIT(
const int v,
C& d) {
return ERR_CONV;};
147 inline static int toINT(
const int v,
I& d) {d=v;
return 0;};
148 inline static int toFL(
const int v,
D& d) {d=v;
return 0;};
149 inline static int toCMPX(
const int v, Z& d) {d.re=v; d.im=0;
return 0;};
152 inline static int fromB01(
long& v,
const B d) {v=d;
return 0;};
153 inline static int fromLIT(
long& v,
const C d) {v=d;
return 0;};
154 inline static int fromINT(
long& v,
const I d) {v=d;
return 0;};
155 inline static int fromFL(
long& v,
const D d) {
return ERR_CONV;};
156 inline static int fromCMPX(
long& v,
const Z d) {
return ERR_CONV;};
157 inline static int toB01(
const long v,
B& d) {
return ERR_CONV;};
158 inline static int toLIT(
const long v,
C& d) {
return ERR_CONV;};
159 inline static int toINT(
const long v,
I& d) {d=v;
return 0;};
160 inline static int toFL(
const long v,
D& d) {d=v;
return 0;};
161 inline static int toCMPX(
const long v, Z& d) {d.re=v; d.im=0;
return 0;};
164 inline static int fromB01(
long long& v,
const B d) {v=d;
return 0;};
165 inline static int fromLIT(
long long& v,
const C d) {v=d;
return 0;};
166 inline static int fromINT(
long long& v,
const I d) {v=d;
return 0;};
167 inline static int fromFL(
long long& v,
const D d) {
return ERR_CONV;};
168 inline static int fromCMPX(
long long& v,
const Z d) {
return ERR_CONV;};
169 inline static int toB01(
const long long v,
B& d) {
return ERR_CONV;};
170 inline static int toLIT(
const long long v,
C& d) {
return ERR_CONV;};
171 inline static int toINT(
const long long v,
I& d) {d=v;
return 0;};
172 inline static int toFL(
const long long v,
D& d) {d=v;
return 0;};
173 inline static int toCMPX(
const long long v, Z& d) {d.re=v; d.im=0;
return 0;};
176 inline static int fromB01(
double& v,
const B d) {v=d;
return 0;};
177 inline static int fromLIT(
double& v,
const C d) {v=d;
return 0;};
178 inline static int fromINT(
double& v,
const I d) {v=d;
return 0;};
179 inline static int fromFL(
double& v,
const D d) {v=d;
return 0;};
180 inline static int fromCMPX(
double& v,
const Z d) {
return ERR_CONV;};
181 inline static int toB01(
const double v,
B& d) {
return ERR_CONV;};
182 inline static int toLIT(
const double v,
C& d) {
return ERR_CONV;};
183 inline static int toINT(
const double v,
I& d) {d=v;
return 0;};
184 inline static int toFL(
const double v,
D& d) {d=v;
return 0;};
185 inline static int toCMPX(
const double v, Z& d) {d.re=v; d.im=0;
return 0;};
188 inline static int fromB01(std::complex<double>& v,
const B d) {
190 inline static int fromLIT(std::complex<double>& v,
const C d) {
192 inline static int fromINT(std::complex<double>& v,
const I d) {
194 inline static int fromFL(std::complex<double>& v,
const D d) {
196 inline static int fromCMPX(std::complex<double>& v,
const Z d) {
197 std::complex<double> c(d.re, d.im); v=c;
return 0;};
198 inline static int toB01(
const std::complex<double> v,
B& d) {
200 inline static int toLIT(
const std::complex<double> v,
C& d) {
202 inline static int toINT(
const std::complex<double> v,
I& d) {
204 inline static int toFL(
const std::complex<double> v,
D& d) {
206 inline static int toCMPX(
const std::complex<double> v, Z& d) {
207 d.re=v.real(); d.im=v.imag();
return 0;};
220 if (give_up_ownership)
hdr->
flag|=OWNED_BY_J;
227 const static int OWNED_BY_J=131072;
229 const static int OWNED_BY_JPLUS=262144;
242 template<
class T>
inline int get(T& v,
const int i)
const {
258 template<
class T>
inline int set(
const int i,
const T v) {
273 template<
class T>
int get(std::vector<T>& v)
const {
287 case T_FL:
for(
int i=0;i<
hdr->
n;i++)
304 template<
class T>
int get(T& v);
361 assert((dimension>=0)&&(dimension<
rank()));
362 return shape()[dimension];
374 inline const int size()
const {
476 for (
int i=0;i<n;i++) {
489 return ((T*)
data())[i];
497 return ((T*)
data())[i];
516 assert(
rank()==1);
return ((T*)
data())[i0];
522 assert(
rank()==1);
return ((T*)
data())[i0];
616 const I l3,
const I l4) {
664 assert(
rank()==subscripts.size());
666 for(
int i=0;i<subscripts.size();i++) pos=pos*
extent(i)+subscripts[i];
667 return ((T*)
data())[pos];
672 const T&
operator()(
const std::vector<I> &subscripts)
const {
673 assert(
rank()==subscripts.size());
675 for(
int i=0;i<subscripts.size();i++) pos=pos*
extent(i)+subscripts[i];
676 return ((T*)
data())[pos];
684 for(
int i=0;i<
rank();i++) pos=pos*
extent(i)+subscripts[i];
685 return ((T*)
data())[pos];
693 for(
int i=0;i<
rank();i++) pos=pos*
extent(i)+subscripts[i];
694 return ((T*)
data())[pos];
Typed variant of jarray, performs automatic type conversion on instantiation.
Definition jarray.h:454
const T & operator()(const I *subscripts) const
Convenient read-only access to n-D array.
Definition jarray.h:691
const T & operator()(const I i0) const
Convenient read-only access to 1-D array.
Definition jarray.h:521
const T & operator()(const I i0, const I i1, const I i2, const I i3) const
Convenient read-only access to 4-D array.
Definition jarray.h:603
T & operator()(const I i0, const I i1)
Conveniently access 2-D array.
Definition jarray.h:537
jarray_of_type(jengine *je_)
Conveniently allocate scalar.
Definition jarray.h:502
T & operator()(const I i0, const I i1, const I i2, const I i3)
Conveniently access 4-D array.
Definition jarray.h:592
const T & operator()(const I i0, const I i1, const I i2, const I i3, const I i4) const
Convenient read-only access to 5-D array.
Definition jarray.h:639
jarray_of_type(jengine *je_, const I l0)
Conveniently allocate 1-D array.
Definition jarray.h:509
T & operator()(const I i0, const I i1, const I i2, const I i3, const I i4)
Conveniently access 5-D array.
Definition jarray.h:627
jarray_of_type(jengine *je_, const I l0, const I l1, const I l2)
Conveniently allocate 3-D array.
Definition jarray.h:553
jarray_of_type(const jarray &ja)
Initialize with type conversion.
Definition jarray.h:470
T & operator()(const I *subscripts)
Conveniently access n-D array.
Definition jarray.h:682
jarray_of_type(jengine *je_, const I l0, const I l1, const I l2, const I l3)
Conveniently allocate 4-D array.
Definition jarray.h:581
const T & operator()(const I i0, const I i1, const I i2) const
Convenient read-only access to 3-D array.
Definition jarray.h:571
T & operator()(const std::vector< I > &subscripts)
Conveniently access n-D array.
Definition jarray.h:663
jarray_of_type(jengine *je_, const I rank, const I *shape)
Conveniently allocate n-D array.
Definition jarray.h:649
T & operator()(const I i0)
conveniently access 1-D array.
Definition jarray.h:515
jarray_of_type(jengine *je_, const I l0, const I l1)
Conveniently allocate 2-D array.
Definition jarray.h:529
T & operator()(const I i0, const I i1, const I i2)
Conveniently access 3-D array.
Definition jarray.h:562
jarray_of_type(jengine *je_, const I l0, const I l1, const I l2, const I l3, const I l4)
Conveniently allocate 5-D array.
Definition jarray.h:615
const T & operator()(const I i0, const I i1) const
Convenient read-only access to 2-D array.
Definition jarray.h:544
jarray_of_type(jengine *je_, const std::vector< I > &shape)
Conveniently allocate n-D array.
Definition jarray.h:656
const T & operator[](const I i) const
Direct read-only access to an element of ravel.
Definition jarray.h:495
T & operator[](const I i)
Directly access element of ravel.
Definition jarray.h:487
const T & operator()(const std::vector< I > &subscripts) const
Convenient read-only access to n-D array.
Definition jarray.h:672
C++ representation of J array.
Definition jarray.h:25
long I
integer type, equivalent to J
Definition jarray.h:36
errorType
error codes
Definition jarray.h:49
@ ERR_CONV
data type conversion error
Definition jarray.h:50
@ ERR_SHAPE
shape mismatch
Definition jarray.h:51
jarray(jengine *je_, const std::string &str)
Creates T_LIT vector from C++ string.
bool isValid() const
Returns true if the array is valid.
Definition jarray.h:335
const int size() const
Number of elements in ravel.
Definition jarray.h:374
void shape(std::vector< I > &shape) const
Copies array shape into STL vector.
Definition jarray.h:367
double D
floating point type, equivalent to J
Definition jarray.h:38
int get(std::vector< T > &v) const
Fits ravel of the array into the specified STL vector.
Definition jarray.h:273
I * data() const
Returns pointer to the beginning of the array data.
Definition jarray.h:382
int extent(int dimension) const
Returns the extent of the specified dimension, element of shape.
Definition jarray.h:360
I getRefcount() const
returns the array refcount
Definition jarray.h:234
I getHeader(bool give_up_ownership=true) const
Definition jarray.h:219
bool write(std::ostream &out)
Writes binary representation of this array into the specified output stream.
bool operator==(const jarray &rhs) const
Performs by-element comparison and return true if two arrays are the same.
const I type() const
Returns array type.
Definition jarray.h:341
bool allocate(jengine *je_, elementType type, const I rank, const I *shape)
Allocates new array in memory.
jengine * getEngine() const
Returns pointer to jengine, managing memory of this array.
Definition jarray.h:391
jarray & operator=(const jarray &other)
Shortcut to assign.
Definition jarray.h:431
~jarray()
Decrements refcount, frees array memory, if necessary.
jarray(jengine *je_, std::istream &in)
Loads the array from binary representation in a stream.
int get(T &v, const int i) const
Obtains the value of a specified element of ravel.
Definition jarray.h:242
jengine * je
Pointer to jengine, managing the memory of this array.
Definition jarray.h:95
jarray(jengine *je_, elementType type, I rank, I *shape)
Creates new multidimensional array of the given J type.
const I rank() const
Rank (dimensionality) of the array.
Definition jarray.h:347
char B
byte type, equivalent to J
Definition jarray.h:30
short S
short int type, equivalent to J
Definition jarray.h:32
jarray::I esize() const
Size (in bytes) of the single element of this array.
void release()
Decrements refcount and frees memory, if necessary.
int get(T &v)
Attempts to fit the whole array into the specified type.
jarray & assign(const jarray &other)
Assigns another array to this one (increments refcount and frees memory, if necessary)
char C
literal type, equivalent to J
Definition jarray.h:31
jarray()
Invalid array, a valid array can be assigned to it.
jarray(jengine *je_, elementType type, const std::vector< I > &shape)
Creates new multidimensional array of the given J type.
elementType
Constants for possible array element types.
Definition jarray.h:55
@ T_FL
D double (IEEE floating point)
Definition jarray.h:59
@ T_B01
B boolean
Definition jarray.h:56
@ T_LIT
C literal (character)
Definition jarray.h:57
@ T_CMPX
Z complex
Definition jarray.h:60
@ T_INT
I integer
Definition jarray.h:58
header * hdr
Pointer to the array header, NULL for invalid array.
Definition jarray.h:94
int set(const int i, const T v)
Assigns the value of the specified element of ravel.
Definition jarray.h:258
void addhash(SHA1 &sha)
Add this array (both shape and values) to the hash.
void grab() const
Increments refcount.
I * shape() const
Returns pointer to the first element of the shape.
Definition jarray.h:353
jarray(const jarray &other)
Makes a copy of another array (increments refcount).
static jarray::I esize(elementType type)
Size (in bytes) of the particular data type.
jarray(jengine *je_, void *hdr_)
Instantiates on top of an existing J array.
Interface to dynamically loaded J engine.
Definition jengine.h:13
std::ostream & operator<<(std::ostream &stream, const jarray &array)
prints ASCII representation of the array
Layout of two words before every array, responsible for J memory management.
Definition jarray.h:99
I * a
Definition jarray.h:99
complex type, equivalent to J
Definition jarray.h:40
D im
imaginary part
Definition jarray.h:42
D re
real part
Definition jarray.h:41