Commit 079d3a6f authored by Per Bothner's avatar Per Bothner

* GeneralArray.java: Fix calculation of 'simple' property.

Fixes GitLab issue #67 "array->vector on array from share-array
gives incorrect vector".
* Arrays.java (shareArray): Tweak due to GeneralArray changes.
* arr-test.scm: Some tests based on GibLab issues #66 and #67.
parent 8e1e5548
Pipeline #125546869 failed with stage
in 5 minutes and 26 seconds
......@@ -240,8 +240,8 @@ public class Arrays
AVector base = array instanceof GeneralArray
? ((GeneralArray) array).getBase()
: (AVector) array;
result.setBase(base);
result.setStrides(offsets, offset0);
result.setBase(base);
return result;
}
......
2020-03-11 Per Bothner <per@bothner.com>
* Arrays.java (shareArray): Tweak due to GeneralArray changes.
* IsEqual.java (match): Fix thinko comparing arrays.
2019-12-24 Per Bothner <per@bothner.com>
......
2020-03-11 Per Bothner <per@bothner.com>
* GeneralArray.java: Fix calculation of 'simple' property.
Fixes GitLab issue #67 "array->vector on array from share-array
gives incorrect vector".
2020-03-04 Per Bothner <per@bothner.com>
* FlattenedArray.java (flatten): Check for 'simple' array first.
......
......@@ -50,26 +50,18 @@ public class GeneralArray<E> extends TransformedArray<E>
}
protected void init(AVector<E> base, int[] dimensions, int[] lowBounds,
int[] strides, int offset) {
this.base = base;
simple = strides == null && offset == 0;
int d = dimensions.length;
if (lowBounds == null) {
lowBounds = zeros;
if (d > lowBounds.length)
lowBounds = new int[d];
}
if (strides == null) {
strides = new int[d];
int n = 1;
for (int i = d; --i >= 0; ) {
strides[i] = n;
n *= dimensions[i];
}
}
this.strides = strides;
this.dimensions = dimensions;
this.lowBounds = lowBounds;
this.offset = offset;
if (base != null)
this.setBase(base);
}
private static int getSize(int[] dimensions) {
......@@ -92,15 +84,43 @@ public class GeneralArray<E> extends TransformedArray<E>
return array;
}
public AVector<E> getBase() { return (AVector<E>) base; }
/** Calculates 'simple' and 'strides' (if defaulted).
* Requires 'base' and 'dimensions' to be already set.
*/
void checkSimple() {
boolean simple = offset == 0;
int d = dimensions.length;
int n = 1;
if (strides == null) {
strides = new int[d];
for (int i = d; --i >= 0; ) {
strides[i] = n;
n *= dimensions[i];
}
} else {
for (int i = d; simple && --i >= 0; ) {
if (strides[i] != n)
simple = false;
n *= dimensions[i];
}
}
this.simple = simple && n == base.getSize();
}
public void setBase(AVector<E> base) {
if (this.base != null)
throw new IllegalStateException();
this.base = base;
checkSimple();
}
public void setBase(E[] data) {
setBase(new FVector(data));
}
/** Must be called before setBase */
public void setStrides(int[] strides, int offset) {
if (this.base != null)
throw new IllegalStateException();
this.strides = strides;
this.offset = offset;
}
......
2020-03-11 Per Bothner <per@bothner.com>
* arr-test.scm: Some tests based on GibLab issues #66 and #67.
2019-12-24 Per Bothner <per@bothner.com>
* charset1.scm: New tests for GitLab issue #63
......
;; -*- coding: utf-8 -*-
(test-begin "arrays" 234)
(test-begin "arrays" 244)
;;; array test
;;; 2001 Jussi Piitulainen
......@@ -622,4 +622,25 @@
002003
╚═══╧═══╝}
(format-array #2u32@2@3((1 2) (2 3)) "~3,'0d"))
;; Some tests relating to GitLab issues #66 and #67
(let* ((v1 (vector 100 101 102 103))
(a1a (make-array (shape 0 4) @v1))
(a1b (array-reshape v1 (shape 0 4)))
(a2a (make-array (shape 0 2 0 2) @v1))
(s2b (shape 0 2 1 3))
(a2b (array-reshape v1 s2b))
(a3 (share-array a1b (shape 0 2) values)))
(test-equal a1a a1b)
(test-assert (not (equal? a2a a2b)))
(test-assert (equal? (array-reshape a2a s2b) a2b))
(test-equal v1 (array->vector a1a))
(test-eq v1 (array->vector a1b))
(test-equal v1 (array->vector a2a))
(test-eq v1 (array->vector a2b))
(test-equal #(100 101) a3)
(test-equal #(100 101) (array->vector a3))
(test-equal #(100 101) (array-flatten a3))
)
(test-end)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment