jplus-0.4.7
jarray.h
Go to the documentation of this file.
1/* -*- mode: c++; indent-tabs-mode:nil -*- */
2#ifndef JARRAY_H
3#define JARRAY_H
4
5#include <vector>
6#include <string>
7#include <complex>
8#include <istream>
9#include <ostream>
10#include <cassert>
11#include "sha1.h"
12
13class jengine;
14
25class jarray {
26public:
27 // C types, corresponding to J types
28 // TODO: these are only for 32 bit linux, need ifdefs to cover
29 // additional platforms
30 typedef char B;
31 typedef char C;
32 typedef short S;
33#if _UNIX64
34 typedef long long I;
35#else
36 typedef long I;
37#endif
38 typedef double D;
40 typedef struct {
41 D re,
43 } Z;
44
45 friend class jengine;
46
47public:
49 enum errorType {
51 ERR_SHAPE=11
52 };
53
56 T_B01 =1,
57 T_LIT =2,
58 T_INT =4,
59 T_FL =8,
60 T_CMPX =16
61 };
62 // numeric constants, corresponding to J 7.01 types.
63 // Not all of J types are supported, but the supported ones have
64 // the full set of automatic widening conversions.
65 //const static I T_B01 =1; /**< B boolean */
66 //const static I T_LIT =2; /**< C literal (character) */
67 //const static I T_INT =4; /**< I integer */
68 //const static I T_FL =8; /**< D double (IEEE floating point) */
69 //const static I T_CMPX =16; /**< Z complex */
70 //const static I T_BOX =32; /**< A boxed */
71 //const static I T_XNUM =64; /**< X extended precision integer */
72 //const static I T_RAT =128; /**< Q rational number */
73 //const static I T_SB01 =1024; /**< P sparse boolean */
74 //const static I T_SLIT =2048; /**< P sparse literal (character) */
75 //const static I T_SINT =4096; /**< P sparse integer */
76 //const static I T_SFL =8192; /**< P sparse floating point */
77 //const static I T_SCMPX=16384; /**< P sparse complex */
78 //const static I T_SBOX =32768; /**< P sparse boxed */
79 //const static I T_SBT =65536; /**< SB symbol */
80 //const static I T_C2T =131072; /**< C2 unicode (2-byte characters) */
81
82protected:
99 typedef struct {I*a;S j;C mflag,unused;} MS;
100
110 bool allocate(jengine *je_, elementType type, const I rank, const I* shape);
111
113 // conversions: T=bool
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;};
124
125 // conversions: T=char
126 // it may be more convenient to obtain literal array as a string
127 // via get(string&) method.
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;};
138
139 // conversions: T=int
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;};
150
151 // conversions: T=long
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;};
162
163 // conversions: T=long long
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;};
174
175 // conversions: T=double
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;};
186
187 // conversions: T=complex<double>
188 inline static int fromB01(std::complex<double>& v, const B d) {
189 return ERR_CONV;};
190 inline static int fromLIT(std::complex<double>& v, const C d) {
191 v=d; return 0;};
192 inline static int fromINT(std::complex<double>& v, const I d) {
193 v=d; return 0;};
194 inline static int fromFL(std::complex<double>& v, const D d) {
195 v=d; return 0;};
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) {
199 return ERR_CONV;};
200 inline static int toLIT(const std::complex<double> v, C& d) {
201 return ERR_CONV;};
202 inline static int toINT(const std::complex<double> v, I& d) {
203 return ERR_CONV;};
204 inline static int toFL(const std::complex<double> v, D& d) {
205 return ERR_CONV;};
206 inline static int toCMPX(const std::complex<double> v, Z& d) {
207 d.re=v.real(); d.im=v.imag(); return 0;};
211 void grab() const;
212
214 void release();
215
216 // returns pointer to the header and (if parameter is "true", which is
217 // default) marks the array as owned by J preventing its memory from
218 // being freed as it goes out of scope.
219 inline I getHeader(bool give_up_ownership=true) const {
220 if (give_up_ownership) hdr->flag|=OWNED_BY_J;
221 return (I)hdr;
222 };
223
224private:
225 // flag, marking the array as J owned, preventing its memory from
226 // being freed when the array goes out of scope.
227 const static int OWNED_BY_J=131072;
228 // marks the array as being allocated on heap without J assistance
229 const static int OWNED_BY_JPLUS=262144;
230
231public:
234 I getRefcount() const {return hdr->refcnt;};
235
242 template<class T> inline int get(T& v, const int i) const {
243 switch(hdr->type) {
244 case T_B01: return fromB01(v,((B*)(((B*)hdr)+hdr->offset))[i]);
245 case T_LIT: return fromLIT(v,((C*)(((B*)hdr)+hdr->offset))[i]);
246 case T_INT: return fromINT(v,((I*)(((B*)hdr)+hdr->offset))[i]);
247 case T_FL: return fromFL(v,((D*)(((B*)hdr)+hdr->offset))[i]);
248 case T_CMPX: return fromCMPX(v,((Z*)(((B*)hdr)+hdr->offset))[i]);
249 default: return ERR_CONV;
250 };
251 };
252
258 template<class T> inline int set(const int i, const T v) {
259 switch(hdr->type) {
260 case T_B01: return toB01(v,((B*)(((B*)hdr)+hdr->offset))[i]);
261 case T_LIT: return toLIT(v,((C*)(((B*)hdr)+hdr->offset))[i]);
262 case T_INT: return toINT(v,((I*)(((B*)hdr)+hdr->offset))[i]);
263 case T_FL: return toFL(v,((D*)(((B*)hdr)+hdr->offset))[i]);
264 case T_CMPX: return toCMPX(v,((Z*)(((B*)hdr)+hdr->offset))[i]);
265 default: return ERR_CONV;
266 };
267 };
268
273 template<class T> int get(std::vector<T>& v) const {
274 std::vector<T> r;
275 r.reserve(hdr->n);
276 int e;
277 switch(hdr->type) {
278 case T_B01: for(int i=0;i<hdr->n;i++)
279 if (e=fromB01(v[i],((B*)(((B*)hdr)+hdr->offset))[i])) return e;
280 break;
281 case T_LIT: for(int i=0;i<hdr->n;i++)
282 if (e=fromLIT(v[i],((C*)(((B*)hdr)+hdr->offset))[i])) return e;
283 break;
284 case T_INT: for(int i=0;i<hdr->n;i++)
285 if (e=fromINT(v[i],((I*)(((B*)hdr)+hdr->offset))[i])) return e;
286 break;
287 case T_FL: for(int i=0;i<hdr->n;i++)
288 if (e=fromFL(v[i],((D*)(((B*)hdr)+hdr->offset))[i])) return e;
289 break;
290 case T_CMPX: for(int i=0;i<hdr->n;i++)
291 if (e=fromCMPX(v[i],((Z*)(((B*)hdr)+hdr->offset))[i])) return e;
292 break;
293 default: return ERR_CONV;
294 };
295 r.swap(v);
296 return 0;
297 };
298
304 template<class T> int get(T& v);
305
308
313 jarray(jengine *je_, std::istream& in);
314
319
322
325 void addhash(SHA1 &sha);
326
331 bool write(std::ostream& out);
332
335 inline bool isValid() const {
336 return hdr!=NULL;
337 };
338
341 inline const I type() const {
342 return hdr->type;
343 };
344
347 inline const I rank() const {
348 return hdr->rank;
349 };
350
353 inline I* shape() const {
354 return &hdr->shape[0];
355 };
356
360 int extent(int dimension) const {
361 assert((dimension>=0)&&(dimension<rank()));
362 return shape()[dimension];
363 };
364
367 inline void shape(std::vector<I> &shape) const {
368 std::vector<I> r(&hdr->shape[0],&hdr->shape[rank()]);
369 r.swap(shape);
370 };
371
374 inline const int size() const {
375 int n=1;
376 for (int i=0;i<rank();i++) n*=hdr->shape[i];
377 return n;
378 };
379
382 inline I* data() const {
383 return (I*)(((B*)hdr)+hdr->offset);
384 };
385
392 return je;
393 };
394
398 jarray(jengine *je_, void *hdr_);
399
406
411 jarray(jengine *je_, elementType type, const std::vector<I>& shape);
412
416 jarray(jengine *je_,const std::string &str);
417
420 jarray(const jarray &other);
421
426 jarray& assign(const jarray& other);
427
431 inline jarray& operator=(const jarray& other) {
432 return assign(other);
433 };
434
440 bool operator== ( const jarray& rhs ) const;
441
444};
445
450std::ostream& operator<< (std::ostream& stream, const jarray& array);
451
454template<class T> class jarray_of_type: public jarray {
455private:
456 static elementType jtype(I dummy) {return T_INT;};
457 static elementType jtype(D dummy) {return T_FL;};
458 static elementType jtype(Z dummy) {return T_CMPX;};
459 static elementType jtype(std::complex<D> dummy) {return T_CMPX;};
460
461public:
471 T dummy;
472 elementType type=jtype(dummy);
473 if (type!=ja.type()) { // make an independent copy and convert type
474 allocate(ja.getEngine(), type, ja.rank(), ja.shape());
475 int n=ja.size();
476 for (int i=0;i<n;i++) {
477 T v;
478 ja.get(v,i);
479 set(i,v);
480 };
481 } else assign(ja); // type is the same, direct access
482 };
483
487 T& operator[](const I i) {
488 // assert((i>=0)&&(i<size());
489 return ((T*)data())[i];
490 };
491
495 const T& operator[](const I i) const {
496 // assert((i>=0)&&(i<size());
497 return ((T*)data())[i];
498 };
499
503 T dummy; I shape[]={}; allocate(je_, jtype(dummy), 0, shape);
504 };
505
509 jarray_of_type(jengine *je_, const I l0) {
510 T dummy; I shape[]={l0}; allocate(je_, jtype(dummy), 1, shape);
511 };
515 T& operator()(const I i0) {
516 assert(rank()==1); return ((T*)data())[i0];
517 };
521 const T& operator()(const I i0) const {
522 assert(rank()==1); return ((T*)data())[i0];
523 };
524
529 jarray_of_type(jengine *je_, const I l0, const I l1) {
530 T dummy; I shape[]={l0,l1}; allocate(je_,jtype(dummy), 2, shape);
531 };
532
537 T& operator()(const I i0,const I i1) {
538 assert(rank()==2); return ((T*)data())[i0*extent(1)+i1];
539 };
544 const T& operator()(const I i0,const I i1) const {
545 assert(rank()==2); return ((T*)data())[i0*extent(1)+i1];
546 };
547
553 jarray_of_type(jengine *je_, const I l0, const I l1, const I l2) {
554 T dummy; I shape[]={l0,l1,l2}; allocate(je_, jtype(dummy), 3, shape);
555 };
556
562 T& operator()(const I i0,const I i1,const I i2) {
563 assert(rank()==3); return ((T*)data())[(i0*extent(1)+i1)*extent(2)+i2];
564 };
565
571 const T& operator()(const I i0,const I i1,const I i2) const {
572 assert(rank()==3); return ((T*)data())[(i0*extent(1)+i1)*extent(2)+i2];
573 };
574
581 jarray_of_type(jengine *je_, const I l0, const I l1, const I l2,
582 const I l3) {
583 T dummy; I shape[]={l0,l1,l2,l3}; allocate(je_,jtype(dummy), 4, shape);
584 };
585
592 T& operator()(const I i0,const I i1,const I i2,const I i3) {
593 assert(rank()==4);
594 return ((T*)data())[((i0*extent(1)+i1)*extent(2)+i2)*extent(3)+i3];
595 };
596
603 const T& operator()(const I i0,const I i1,const I i2,const I i3) const {
604 assert(rank()==4);
605 return ((T*)data())[((i0*extent(1)+i1)*extent(2)+i2)*extent(3)+i3];
606 };
607
615 jarray_of_type(jengine *je_, const I l0, const I l1, const I l2,
616 const I l3, const I l4) {
617 T dummy; I shape[]={l0,l1,l2,l3,l4}; allocate(je_,jtype(dummy), 5, shape);
618 };
619
627 T& operator()(const I i0,const I i1,const I i2,const I i3,const I i4) {
628 assert(rank()==4);
629 return ((T*)data())[(((i0*extent(1)+i1)*extent(2)+i2)*extent(3)+i3)*extent(4)+i4];
630 };
631
639 const T& operator()(const I i0,const I i1,const I i2,const I i3,const I i4) const {
640 assert(rank()==4);
641 return ((T*)data())[(((i0*extent(1)+i1)*extent(2)+i2)*extent(3)+i3)*extent(4)+i4];
642 };
643
644
649 jarray_of_type(jengine *je_, const I rank, const I *shape) {
650 T dummy; allocate(je_, jtype(dummy), rank, shape);
651 };
652
656 jarray_of_type(jengine *je_, const std::vector<I> &shape) {
657 T dummy; allocate(je_, jtype(dummy), shape.size(), &shape[0]);
658 };
659
663 T& operator()(const std::vector<I> &subscripts) {
664 assert(rank()==subscripts.size());
665 I pos=0;
666 for(int i=0;i<subscripts.size();i++) pos=pos*extent(i)+subscripts[i];
667 return ((T*)data())[pos];
668 };
672 const T& operator()(const std::vector<I> &subscripts) const {
673 assert(rank()==subscripts.size());
674 I pos=0;
675 for(int i=0;i<subscripts.size();i++) pos=pos*extent(i)+subscripts[i];
676 return ((T*)data())[pos];
677 };
682 T& operator()(const I *subscripts) {
683 I pos=0;
684 for(int i=0;i<rank();i++) pos=pos*extent(i)+subscripts[i];
685 return ((T*)data())[pos];
686 };
691 const T& operator()(const I *subscripts) const {
692 I pos=0;
693 for(int i=0;i<rank();i++) pos=pos*extent(i)+subscripts[i];
694 return ((T*)data())[pos];
695 };
696
697};
698#endif
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
J array header.
Definition jarray.h:84
I type
type of array elements (one of T_XXX) .
Definition jarray.h:88
I rank
array rank
Definition jarray.h:91
I shape[1]
elements of shape
Definition jarray.h:92
I offset
offset of data w.r.t header.
Definition jarray.h:85
I refcnt
reference count
Definition jarray.h:89
I maxbytes
bytes allocated.
Definition jarray.h:87
I n
number of elements in ravel
Definition jarray.h:90
I flag
flags, jarray sets couple of its own.
Definition jarray.h:86