Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Commit 27d9fd2

Browse files
Merge pull request #56 from phpsci/1.0-dev
1.0 dev
2 parents e1a2a7e + 8524ef1 commit 27d9fd2

40 files changed

+2396
-327
lines changed

config.h.in~

Lines changed: 0 additions & 82 deletions
This file was deleted.

config.m4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ PHP_NEW_EXTENSION(carray,
110110
kernel/convert_type.c \
111111
kernel/trigonometric.c \
112112
kernel/matlib.c \
113+
kernel/statistics.c \
114+
kernel/arraytypes.c \
113115
kernel/join.c \
114116
kernel/ctors.c \
115117
kernel/scalar.c \
118+
kernel/round.c \
116119
kernel/getset.c \
117120
kernel/common/strided_loops.c \
118121
kernel/convert_datatype.c \

docs/routines/indexing.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
1-
## take
1+
# Indexing Routines
22

3-
## take_along_axis
3+
---
44

5-
## choose
5+
## diagonal
66

7-
## compress
7+
```php
8+
public static diagonal($a, int $offset = 0, int $axis1 = 0, int $axis2 = 0) : CArray
9+
```
10+
> Return specified diagonals.
811
9-
## diag
12+
> If a is 2-D, returns the diagonal of a with the given offset, i.e., the collection of elements of the
13+
form `$a[i][i+offset]`. If a has more than two dimensions, then the axes specified by axis1 and axis2 are used to
14+
determine the 2-D sub-array whose diagonal is returned. The shape of the resulting array can be determined by
15+
removing axis1 and axis2 and appending an index to the right equal to the size of the resulting diagonals.
1016

11-
## diagonal
17+
##### Parameters
18+
19+
`CArray|Array` **$a** - Input array.
20+
21+
`CArray|Array` **$offset** (optional) - Offset of the diagonal from the main diagonal. Can be positive or negative. Defaults to
22+
main diagonal (0).
23+
24+
`CArray|Array` **$axis1** (optional) - Axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken.
25+
Defaults to first axis (0).
26+
27+
`CArray|Array` **$axis2** (optional) - Axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be
28+
taken. Defaults to second axis (1).
29+
30+
##### Returns
31+
32+
`CArray` Diagonals of `$a`.
33+
34+
##### Examples
35+
36+
**Example 1**
37+
```php
38+
$A = CArray::arange(4);
39+
$A = CArray::reshape($A, [2, 2]);
40+
echo CArray::diagonal($A);
41+
```
42+
````
43+
[ 0 3 ]
44+
````
1245

13-
## select

docs/routines/ones_and_zeros.md

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,77 @@
1-
## eye
1+
# Ones and Zeros Routines
2+
3+
---
24

35
## identity
46

5-
## ones
7+
```php
8+
public static identity($n) : CArray
9+
```
10+
> Return the identity array.
11+
12+
> The identity array is a square array with ones on the main diagonal.
13+
14+
##### Parameters
15+
16+
`CArray|Array` **$n** Number of rows (and columns) in `$n x $n` output.
17+
18+
##### Returns
19+
20+
`CArray` `$n x $n` CArray with its main diagonal set to one, and all other elements 0.
21+
22+
##### Examples
23+
24+
**Example 1**
25+
```php
26+
echo CArray::identity(4);
27+
```
28+
```
29+
[[ 1. 0. 0. 0. ]
30+
[ 0. 1. 0. 0. ]
31+
[ 0. 0. 1. 0. ]
32+
[ 0. 0. 0. 1. ]]
33+
```
34+
35+
---
36+
37+
## eye
638

7-
## ones_like
39+
```php
40+
public static eye($n, $m = NULL, $k = 0) : CArray
41+
```
42+
43+
> Return a 2-D array with ones on the diagonal and zeros elsewhere.
44+
45+
##### Parameters
46+
47+
`CArray|Array` **$n** Number of rows in the output.
48+
49+
`CArray|Array` **$m** Number of columns in the output. If NULL, defaults to `$n`.
50+
51+
`CArray|Array` **$k** Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to
52+
an upper diagonal, and a negative value to a lower diagonal.
53+
54+
##### Returns
55+
56+
`CArray` An array where all elements are equal to zero, except for the `$k`-th diagonal, whose values are equal to one.
57+
58+
##### Examples
59+
60+
**Example 1**
61+
```php
62+
echo CArray::eye(3, 3, 1);
63+
```
64+
```
65+
[[ 0. 1. 0. ]
66+
[ 0. 0. 1. ]
67+
[ 0. 0. 0. ]]
68+
```
69+
70+
71+
---
72+
73+
## ones
874

9-
## zeros
75+
---
1076

11-
## zeros_like
77+
## zeros

docs/routines/rearranging.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Rearranging Routines
2+
3+
---
4+
5+
## reshape
6+
7+
```php
8+
public static reshape($a, $newshape) : CArray
9+
```
10+
> Gives a new shape to an array without changing its data.
11+
12+
##### Parameters
13+
14+
`CArray|Array` **$a** Input array.
15+
16+
`CArray|Array` **$newshape** The new shape should be compatible with the original shape. If an integer, then the result
17+
will be a 1-D array of that length.
18+
19+
##### Returns
20+
21+
`CArray` This will be a new view of `$a` if possible; otherwise, it will be a copy.
22+
23+
##### Examples
24+
25+
**Example 1**
26+
```php
27+
$A = CArray::arange(8);
28+
echo CArray::reshape($A, [2, 4]);
29+
```
30+
````
31+
[[ 0 1 2 3 ]
32+
[ 4 5 6 7 ]]
33+
````
34+
35+
---
36+
37+
## flip
38+
39+
```php
40+
public static flip($a) : CArray
41+
```
42+
> Reverse the order of elements in an array
43+
44+
##### Parameters
45+
46+
`CArray|Array` **$a** Input array.
47+
48+
##### Returns
49+
50+
`CArray` A view of `$a` with the entries of axis reversed.
51+
52+
##### Examples
53+
54+
**Example 1**
55+
```php
56+
$A = CArray::arange(8);
57+
echo CArray::flip($A);
58+
```
59+
```
60+
[ 7 6 5 4 3 2 1 0 ]
61+
```

docs/routines/shape.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
---
44

5-
## reshape
6-
75
## ravel
86

97
## CArray::$flat

kernel/alloc.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
void
66
CArrayDescriptor_FREE(CArrayDescriptor * descr)
77
{
8-
efree(descr->f);
9-
efree(descr);
8+
if (descr->refcount <= 0) {
9+
efree(descr->f);
10+
efree(descr);
11+
descr = NULL;
12+
}
1013
}
1114

1215
/**
@@ -72,17 +75,22 @@ CArrayDescriptor_INCREF(CArrayDescriptor * descriptor)
7275
void
7376
CArrayDescriptor_DECREF(CArrayDescriptor * descriptor)
7477
{
75-
descriptor->refcount--;
78+
if (descriptor != NULL) {
79+
descriptor->refcount--;
80+
}
7681
}
7782

7883
void
7984
CArray_Free(CArray * self)
8085
{
86+
if (self->descriptor != NULL) {
87+
if (self->descriptor->refcount <= 0) {
88+
CArrayDescriptor_FREE(self->descriptor);
89+
}
90+
}
8191
if(self->refcount <= 0) {
8292
efree(self->dimensions);
8393
efree(self->strides);
84-
efree(self->descriptor->f);
85-
efree(self->descriptor);
8694
efree(self->data);
8795
efree(self);
8896
} else {

0 commit comments

Comments
 (0)