diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel1.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel1.java index ecff42ae9..cb5adefdb 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel1.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel1.java @@ -48,15 +48,6 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, X, Y); - if (X.isSparse() && !Y.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().dot(n, alpha, X, Y); - } else if (!X.isSparse() && Y.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().dot(n, alpha, Y, X); - } else if (X.isSparse() && Y.isSparse()) { - // TODO - MKL doesn't contain such routines - return 0; - } - if (X.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, X, Y); return ddot(n, X, BlasBufferUtil.getBlasStride(X), Y, BlasBufferUtil.getBlasStride(Y)); @@ -100,14 +91,9 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { @Override public double nrm2(INDArray arr) { - if (arr.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().nrm2(arr); - } if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); - if (arr.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().nrm2(arr); - } + if (arr.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, arr); return dnrm2(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); @@ -127,9 +113,6 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { @Override public double asum(INDArray arr) { - if (arr.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().asum(arr); - } if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); @@ -202,9 +185,7 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { */ @Override public int iamax(INDArray arr) { - if (arr.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().iamax(arr); - } + if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); @@ -225,11 +206,7 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { */ @Override public int iamin(INDArray arr) { - if (arr.isSparse()) { - return Nd4j.getSparseBlasWrapper().level1().iamin(arr); - } else { throw new UnsupportedOperationException(); - } } /** @@ -243,11 +220,6 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, x, y); - if (x.isSparse() || y.isSparse()) { - Nd4j.getSparseBlasWrapper().level1().swap(x, y); - return; - } - if (x.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, x, y); dswap(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); @@ -269,10 +241,6 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, x, y); - if (x.isSparse() || y.isSparse()) { - Nd4j.getSparseBlasWrapper().level1().copy(x, y); - return; - } if (x.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, x, y); dcopy(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); @@ -321,9 +289,7 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, x, y); - if (x.isSparse() && !y.isSparse()) { - Nd4j.getSparseBlasWrapper().level1().axpy(n, alpha, x, y); - } else if (x.data().dataType() == DataType.DOUBLE) { + if (x.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, x, y); daxpy(n, alpha, x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } else if (x.data().dataType() == DataType.FLOAT) { @@ -384,9 +350,7 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, X, Y); - if (X.isSparse() && !Y.isSparse()) { - Nd4j.getSparseBlasWrapper().level1().rot(N, X, Y, c, s); - } else if (X.data().dataType() == DataType.DOUBLE) { + if (X.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, X, Y); drot(N, X, BlasBufferUtil.getBlasStride(X), Y, BlasBufferUtil.getBlasStride(X), c, s); } else { @@ -421,9 +385,7 @@ public abstract class BaseLevel1 extends BaseLevel implements Level1 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, X); - if (X.isSparse()) { - Nd4j.getSparseBlasWrapper().level1().scal(N, alpha, X); - } else if (X.data().dataType() == DataType.DOUBLE) + if (X.data().dataType() == DataType.DOUBLE) dscal(N, alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataType.FLOAT) sscal(N, (float) alpha, X, BlasBufferUtil.getBlasStride(X)); diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel2.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel2.java index ea5d8cb01..6114c52d5 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel2.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/BaseLevel2.java @@ -56,11 +56,6 @@ public abstract class BaseLevel2 extends BaseLevel implements Level2 { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, A, X, Y); - if (A.isSparse() && !X.isSparse()) { - Nd4j.getSparseBlasWrapper().level2().gemv(order, transA, alpha, A, X, beta, Y); - return; - } - GemvParameters parameters = new GemvParameters(A, X, Y); if (A.data().dataType() == DataType.DOUBLE) { DefaultOpExecutioner.validateDataType(DataType.DOUBLE, parameters.getA(), parameters.getX(), diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLapack.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLapack.java deleted file mode 100644 index d5aae1675..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLapack.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas.impl; - -import org.nd4j.linalg.api.blas.Lapack; -import org.nd4j.linalg.api.ndarray.INDArray; - -/** - * @author Audrey Loeffel - */ -public class SparseBaseLapack implements Lapack { - @Override - public INDArray getrf(INDArray A) { - return null; - } - - @Override - public INDArray getPFactor(int M, INDArray ipiv) { - return null; - } - - @Override - public INDArray getLFactor(INDArray A) { - return null; - } - - @Override - public INDArray getUFactor(INDArray A) { - return null; - } - - @Override - public void getri(int N, INDArray A, int lda, int[] IPIV, INDArray WORK, int lwork, int INFO) { - - } - - @Override - public void geqrf(INDArray A, INDArray R) { - - } - - @Override - public void potrf(INDArray A, boolean lower) { - - } - - @Override - public int syev(char jobz, char uplo, INDArray A, INDArray V) { - return 0; - } - - @Override - public void gesvd(INDArray A, INDArray S, INDArray U, INDArray VT) { - - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel.java deleted file mode 100644 index 6358a4255..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas.impl; - -/** - * @author Audrey Loeffel - */ -public abstract class SparseBaseLevel { - -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel1.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel1.java deleted file mode 100644 index f886aa161..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel1.java +++ /dev/null @@ -1,364 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas.impl; - -import org.nd4j.linalg.api.blas.Level1; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArray; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner; - -/** - * @author Audrey Loeffel - */ -public abstract class SparseBaseLevel1 extends SparseBaseLevel implements Level1 { - - /** - * computes a vector-vector dot product. - * - * @param n number of accessed element - * @param alpha - * @param X an INDArray - * @param Y an INDArray - * @return the vector-vector dot product of X and Y - */ - @Override - public double dot(long n, double alpha, INDArray X, INDArray Y) { - - if (X instanceof BaseSparseNDArray) { - BaseSparseNDArray sparseX = (BaseSparseNDArray) X; - DataBuffer pointers = sparseX.getVectorCoordinates(); - - switch (X.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, X, Y); - return ddoti(n, X, pointers, Y); - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, X, Y); - return sdoti(n, X, pointers, Y); - case HALF: - DefaultOpExecutioner.validateDataType(DataType.HALF, X, Y); - return hdoti(n, X, pointers, Y); - default: - } - } - throw new UnsupportedOperationException(); - } - - - @Override - public double dot(long n, DataBuffer dx, int offsetX, int incrX, DataBuffer y, int offsetY, int incrY) { - throw new UnsupportedOperationException(); - } - - /** - * Computes the Euclidean norm of a vector. - * - * @param arr a vector - * @return the Euclidean norm of the vector - */ - @Override - public double nrm2(INDArray arr) { - - switch (arr.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, arr); - return dnrm2(arr.length(), arr, 1); - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, arr); - return snrm2(arr.length(), arr, 1); - case HALF: - return hnrm2(arr.length(), arr, 1); - default: - } - throw new UnsupportedOperationException(); - } - - /** - * Compute the sum of magnitude of the vector elements - * - * @param arr a vector - * @return the sum of magnitude of the vector elements - * */ - @Override - public double asum(INDArray arr) { - - switch (arr.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, arr); - return dasum(arr.length(), arr, 1); - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, arr); - return sasum(arr.length(), arr, 1); - case HALF: - DefaultOpExecutioner.validateDataType(DataType.HALF, arr); - return hasum(arr.length(), arr, 1); - default: - } - throw new UnsupportedOperationException(); - } - - - @Override - public double asum(long n, DataBuffer x, int offsetX, int incrX) { - throw new UnsupportedOperationException(); - } - - /** - * Find the index of the element with maximum absolute value - * - * @param arr a vector - * @return the index of the element with maximum absolute value - * */ - @Override - public int iamax(INDArray arr) { - switch (arr.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, arr); - return idamax(arr.length(), arr, 1); - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, arr); - return isamax(arr.length(), arr, 1); - case HALF: - DefaultOpExecutioner.validateDataType(DataType.HALF, arr); - return ihamax(arr.length(), arr, 1); - default: - } - throw new UnsupportedOperationException(); - } - - @Override - public int iamax(long n, INDArray arr, int stride) { - throw new UnsupportedOperationException(); - } - - @Override - public int iamax(long n, DataBuffer x, int offsetX, int incrX) { - throw new UnsupportedOperationException(); - } - - - /** - * Find the index of the element with maximum absolute value - * - * @param arr a vector - * @return the index of the element with minimum absolute value - * */ - @Override - public int iamin(INDArray arr) { - switch (arr.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, arr); - return idamin(arr.length(), arr, 1); - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, arr); - return isamin(arr.length(), arr, 1); - case HALF: - DefaultOpExecutioner.validateDataType(DataType.HALF, arr); - return ihamin(arr.length(), arr, 1); - default: - } - throw new UnsupportedOperationException(); - } - - @Override - public void swap(INDArray x, INDArray y) { - throw new UnsupportedOperationException(); - } - - @Override - public void copy(INDArray x, INDArray y) { - // FIXME - for Raver119 :) - throw new UnsupportedOperationException(); - } - - @Override - public void copy(long n, DataBuffer x, int offsetX, int incrX, DataBuffer y, int offsetY, int incrY) { - throw new UnsupportedOperationException(); - } - - /** - * Adds a scalar multiple of compressed sparse vector to a full-storage vector. - * - * @param n The number of element - * @param alpha - * @param x a sparse vector - * @param y a dense vector - * - * */ - @Override - public void axpy(long n, double alpha, INDArray x, INDArray y) { - BaseSparseNDArray sparseX = (BaseSparseNDArray) x; - DataBuffer pointers = sparseX.getVectorCoordinates(); - switch (x.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, x); - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, y); - daxpyi(n, alpha, x, pointers, y); - break; - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, x); - DefaultOpExecutioner.validateDataType(DataType.FLOAT, y); - saxpyi(n, alpha, x, pointers, y); - break; - case HALF: - DefaultOpExecutioner.validateDataType(DataType.HALF, x); - DefaultOpExecutioner.validateDataType(DataType.HALF, y); - haxpyi(n, alpha, x, pointers, y); - break; - default: - throw new UnsupportedOperationException(); - } - } - - @Override - public void axpy(long n, double alpha, DataBuffer x, int offsetX, int incrX, DataBuffer y, int offsetY, int incrY) { - throw new UnsupportedOperationException(); - } - - @Override - public void rotg(INDArray a, INDArray b, INDArray c, INDArray s) { - throw new UnsupportedOperationException(); - } - - /** - * Applies Givens rotation to sparse vectors one of which is in compressed form. - * - * @param N The number of elements in vectors X and Y - * @param X a sparse vector - * @param Y a full-storage vector - * @param c a scalar - * @param s a scalar - * - * */ - @Override - public void rot(long N, INDArray X, INDArray Y, double c, double s) { - - - if (X instanceof BaseSparseNDArray) { - BaseSparseNDArray sparseX = (BaseSparseNDArray) X; - - switch (X.data().dataType()) { - case DOUBLE: - droti(N, X, sparseX.getVectorCoordinates(), Y, c, s); - break; - case FLOAT: - sroti(N, X, sparseX.getVectorCoordinates(), Y, c, s); - break; - case HALF: - hroti(N, X, sparseX.getVectorCoordinates(), Y, c, s); - break; - default: - throw new UnsupportedOperationException(); - } - } else { - throw new UnsupportedOperationException(); - } - } - - @Override - public void rotmg(INDArray d1, INDArray d2, INDArray b1, double b2, INDArray P) { - throw new UnsupportedOperationException(); - } - - /** - * Computes the product of a vector by a scalar. - * - * @param N The number of elements of the vector X - * @param alpha a scalar - * @param X a vector - * */ - @Override - public void scal(long N, double alpha, INDArray X) { - switch (X.data().dataType()) { - case DOUBLE: - dscal(N, alpha, X, 1); - break; - case FLOAT: - sscal(N, alpha, X, 1); - break; - case HALF: - hscal(N, alpha, X, 1); - break; - default: - throw new UnsupportedOperationException(); - } - - } - - @Override - public boolean supportsDataBufferL1Ops() { - return false; - } - - - /* - * =========================================================================== - * Prototypes for level 1 BLAS functions (complex are recast as routines) - * =========================================================================== - */ - - protected abstract double ddoti(long N, INDArray X, DataBuffer indx, INDArray Y); - - protected abstract double sdoti(long N, INDArray X, DataBuffer indx, INDArray Y); - - protected abstract double hdoti(long N, INDArray X, DataBuffer indx, INDArray Y); - - protected abstract double snrm2(long N, INDArray X, int incx); - - protected abstract double dnrm2(long N, INDArray X, int incx); - - protected abstract double hnrm2(long N, INDArray X, int incx); - - protected abstract double dasum(long N, INDArray X, int incx); - - protected abstract double sasum(long N, INDArray X, int incx); - - protected abstract double hasum(long N, INDArray X, int incx); - - protected abstract int isamax(long N, INDArray X, int incx); - - protected abstract int idamax(long N, INDArray X, int incx); - - protected abstract int ihamax(long N, INDArray X, int incx); - - protected abstract int isamin(long N, INDArray X, int incx); - - protected abstract int idamin(long N, INDArray X, int incx); - - protected abstract int ihamin(long N, INDArray X, int incx); - - protected abstract void daxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y); - - protected abstract void saxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y); - - protected abstract void haxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y); - - protected abstract void droti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s); - - protected abstract void sroti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s); - - protected abstract void hroti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s); - - protected abstract void dscal(long N, double a, INDArray X, int incx); - - protected abstract void sscal(long N, double a, INDArray X, int incx); - - protected abstract void hscal(long N, double a, INDArray X, int incx); - -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel2.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel2.java deleted file mode 100644 index 8ef48f474..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel2.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas.impl; - -import org.nd4j.linalg.api.blas.Level2; -import org.nd4j.linalg.api.blas.params.SparseCOOGemvParameters; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner; - -import static org.nd4j.base.Preconditions.checkArgument; - -/** - * @author Audrey Loeffel - */ -public abstract class SparseBaseLevel2 extends SparseBaseLevel implements Level2 { - - - @Override - public void gemv(char order, char transA, double alpha, INDArray A, INDArray X, double beta, INDArray Y) { - checkArgument(A.isMatrix(), "A must be a matrix"); - checkArgument(X.isVector(), "X must be a vector"); - checkArgument(Y.isVector(), "Y must be a vector"); - - SparseCOOGemvParameters parameters = new SparseCOOGemvParameters(A, X, Y); - - - switch (A.data().dataType()) { - case DOUBLE: - DefaultOpExecutioner.validateDataType(DataType.DOUBLE, parameters.getA(), parameters.getX(), - parameters.getY()); - dcoomv(parameters.getAOrdering(), parameters.getM(), parameters.getVal(), parameters.getRowInd(), - parameters.getColInd(), parameters.getNnz(), parameters.getX(), parameters.getY()); - - break; - case FLOAT: - DefaultOpExecutioner.validateDataType(DataType.FLOAT, parameters.getA(), parameters.getX(), - parameters.getY()); - scoomv(parameters.getAOrdering(), parameters.getM(), parameters.getVal(), parameters.getRowInd(), - parameters.getColInd(), parameters.getNnz(), parameters.getX(), parameters.getY()); - - break; - default: - throw new UnsupportedOperationException(); - } - - } - - @Override - public void gbmv(char order, char TransA, int KL, int KU, double alpha, INDArray A, INDArray X, double beta, - INDArray Y) { - - } - - @Override - public void ger(char order, double alpha, INDArray X, INDArray Y, INDArray A) { - - } - - @Override - public void sbmv(char order, char Uplo, double alpha, INDArray A, INDArray X, double beta, INDArray Y) { - - } - - @Override - public void spmv(char order, char Uplo, double alpha, INDArray Ap, INDArray X, double beta, INDArray Y) { - - } - - @Override - public void spr(char order, char Uplo, double alpha, INDArray X, INDArray Ap) { - - } - - @Override - public void spr2(char order, char Uplo, double alpha, INDArray X, INDArray Y, INDArray A) { - - } - - @Override - public void symv(char order, char Uplo, double alpha, INDArray A, INDArray X, double beta, INDArray Y) { - - } - - @Override - public void syr(char order, char Uplo, int N, double alpha, INDArray X, INDArray A) { - - } - - @Override - public void syr2(char order, char Uplo, double alpha, INDArray X, INDArray Y, INDArray A) { - - } - - @Override - public void tbmv(char order, char Uplo, char TransA, char Diag, INDArray A, INDArray X) { - - } - - @Override - public void tbsv(char order, char Uplo, char TransA, char Diag, INDArray A, INDArray X) { - - } - - @Override - public void tpmv(char order, char Uplo, char TransA, char Diag, INDArray Ap, INDArray X) { - - } - - @Override - public void tpsv(char order, char Uplo, char TransA, char Diag, INDArray Ap, INDArray X) { - - } - - @Override - public void trmv(char order, char Uplo, char TransA, char Diag, INDArray A, INDArray X) { - - } - - @Override - public void trsv(char order, char Uplo, char TransA, char Diag, INDArray A, INDArray X) { - - } - - // ---- - protected abstract void scoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, - INDArray x, INDArray y); - - protected abstract void dcoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, - INDArray x, INDArray y); -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel3.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel3.java deleted file mode 100644 index 4057861d1..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/impl/SparseBaseLevel3.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas.impl; - -import org.nd4j.linalg.api.blas.Level3; -import org.nd4j.linalg.api.ndarray.INDArray; - -/** - * @author Audrey Loeffel - */ -public class SparseBaseLevel3 extends SparseBaseLevel implements Level3 { - @Override - public void gemm(char Order, char TransA, char TransB, double alpha, INDArray A, INDArray B, double beta, - INDArray C) { - - } - - @Override - public void gemm(INDArray A, INDArray B, INDArray C, boolean transposeA, boolean transposeB, double alpha, - double beta) { - - } - - @Override - public void symm(char Order, char Side, char Uplo, double alpha, INDArray A, INDArray B, double beta, INDArray C) { - - } - - @Override - public void syrk(char Order, char Uplo, char Trans, double alpha, INDArray A, double beta, INDArray C) { - - } - - @Override - public void syr2k(char Order, char Uplo, char Trans, double alpha, INDArray A, INDArray B, double beta, - INDArray C) { - - } - - @Override - public void trmm(char Order, char Side, char Uplo, char TransA, char Diag, double alpha, INDArray A, INDArray B, - INDArray C) { - - } - - @Override - public void trsm(char Order, char Side, char Uplo, char TransA, char Diag, double alpha, INDArray A, INDArray B) { - - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/params/SparseCOOGemvParameters.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/params/SparseCOOGemvParameters.java deleted file mode 100644 index 44bfeae33..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/params/SparseCOOGemvParameters.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas.params; - -import lombok.Data; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCOO; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.api.ndarray.SparseFormat; -import org.nd4j.linalg.factory.Nd4j; - -/** - * @author Audrey Loeffel - */ -@Data -public class SparseCOOGemvParameters { - - private int m, nnz; - DataBuffer val, rowInd, colInd; - private INDArray a, x, y; - private char aOrdering = 'N'; - - public SparseCOOGemvParameters(INDArray a, INDArray x, INDArray y) { - this.a = a; - this.x = x; - this.y = y; - - if (a.isMatrix() && a.getFormat() == SparseFormat.COO) { - BaseSparseNDArrayCOO coo = (BaseSparseNDArrayCOO) a; - val = coo.getIncludedValues(); - nnz = coo.nnz(); - - // FIXME: int cast - m = (int) coo.rows(); - setIndexes(coo, false); - } - } - - private void setIndexes(BaseSparseNDArrayCOO coo, boolean oneBased) { - int incr = oneBased ? 1 : 0; - int[] idx = coo.getIncludedIndices().asInt(); - int[] rows = new int[nnz]; - int[] cols = new int[nnz]; - for (int i = 0; i < nnz; i++) { - rows[i] = idx[i * 2] + incr; - cols[i] = idx[(i * 2) + 1] + incr; - } - rowInd = Nd4j.createBuffer(rows); - colInd = Nd4j.createBuffer(cols); - } - -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java index 9904168de..7d1acb609 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java @@ -4309,10 +4309,6 @@ public abstract class BaseNDArray implements INDArray, Iterable { if (n == this) return true; - if (n.isSparse()) { - return n.equals(this); - } - if (this.rank() != n.rank()) return false; @@ -5442,56 +5438,6 @@ public abstract class BaseNDArray implements INDArray, Iterable { return array; } - /* - * ------- Sparse methods ------- - */ - - @Override - public DataBuffer getVectorCoordinates() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - } - - @Override - public INDArray toDense() { - return this; - } - - @Override - public int nnz() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - } - - @Override - public SparseFormat getFormat() { - return SparseFormat.NONE; - } - - @Override - public DataBuffer sparseInfoDataBuffer() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - } - - @Override - public int[] flags() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - } - - @Override - public int[] hiddenDimensions() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - } - - @Override - public int[] sparseOffsets() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - } - - @Override - public int underlyingRank() { - throw new UnsupportedOperationException("Not a sparse ndarray"); - - } - protected static DataTypeEx convertType(DataType type) { if (type == DataType.HALF) { return DataTypeEx.FLOAT16; diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseInfoProvider.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseInfoProvider.java deleted file mode 100644 index 160915f5d..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseInfoProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -import org.nd4j.linalg.api.buffer.DataBuffer; - -/** - * @author Audrey Loeffel - */ -abstract public class BaseSparseInfoProvider implements SparseInfoProvider { - @Override - public DataBuffer createSparseInformation(int[] flags, long[] sparseOffsets, int[] hiddenDimensions, - int underlyingRank) { - return createSparseInformation(flags, sparseOffsets, hiddenDimensions, underlyingRank); - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArray.java deleted file mode 100644 index ebe768cac..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArray.java +++ /dev/null @@ -1,1967 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -import org.nd4j.shade.guava.primitives.Ints; -import org.nd4j.shade.guava.primitives.Longs; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import net.ericaro.neoitertools.Generator; -import org.apache.commons.math3.util.FastMath; -import org.nd4j.linalg.api.blas.BlasBufferUtil; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.iter.NdIndexIterator; -import org.nd4j.linalg.api.ops.impl.reduce.floating.Entropy; -import org.nd4j.linalg.api.ops.impl.reduce.floating.LogEntropy; -import org.nd4j.linalg.api.ops.impl.reduce.floating.ShannonEntropy; -import org.nd4j.linalg.api.ops.impl.transforms.custom.Assign; -import org.nd4j.linalg.api.shape.Shape; -import org.nd4j.linalg.exception.ND4JIllegalArgumentException; -import org.nd4j.linalg.exception.ND4JIllegalStateException; -import org.nd4j.linalg.exception.Nd4jNoSuchWorkspaceException; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.indexing.INDArrayIndex; -import org.nd4j.linalg.indexing.SpecifiedIndex; -import org.nd4j.linalg.indexing.conditions.Condition; -import org.nd4j.linalg.primitives.Pair; -import org.nd4j.linalg.string.NDArrayStrings; -import org.nd4j.linalg.util.LinAlgExceptions; - -import java.nio.LongBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.NoSuchElementException; - -import static org.nd4j.linalg.factory.Nd4j.compressDebug; -import static org.nd4j.linalg.factory.Nd4j.createUninitialized; -import static org.nd4j.linalg.factory.Nd4j.preventUnpack; - -/** - * @author Audrey Loeffel - */ -@Slf4j -public abstract class BaseSparseNDArray implements ISparseNDArray { - - /* - * TODO: extends baseNdArray - * */ - - protected static final double THRESHOLD_MEMORY_ALLOCATION = 2; - protected long rows, columns; - protected int rank; - protected Boolean isVector = null; - protected Boolean isMatrix = null; - protected Boolean isScalar = null; - protected long length = -1; - public static final boolean isSparse = true; - protected transient volatile DataBuffer shapeInformation; - protected transient volatile long[] javaShapeInformation; - protected transient volatile DataBuffer sparseInformation; - protected transient DataBuffer shape; - protected transient DataBuffer stride; - - protected DataBuffer reallocate(DataBuffer buffer) { - int newSize = (int) buffer.length() * 2; - DataBuffer newBuffer = Nd4j.createBuffer(newSize); - - switch (buffer.dataType()) { - case INT: - newBuffer.setData(buffer.asInt()); - break; - case DOUBLE: - newBuffer.setData(buffer.asDouble()); - break; - case FLOAT: - newBuffer.setData(buffer.asFloat()); - break; - case HALF: - //TODO - throw new UnsupportedOperationException(); - case COMPRESSED: - //TODO - throw new UnsupportedOperationException(); - default: - throw new UnsupportedOperationException(); - } - return newBuffer; - } - - - @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - @Override - public boolean isColumnVectorOrScalar() { - return isColumnVector() || isScalar(); - } - - @Override - public boolean isRowVectorOrScalar() { - return isRowVector() || isScalar(); - } - - @Override - public INDArray get(INDArray indices) { - if(indices.rank() > 2) { - throw new ND4JIllegalArgumentException("Indices must be a vector or matrix."); - } - - if(indices.rows() == rank()) { - INDArray ret = Nd4j.create(indices.columns()); - - for(int i = 0; i < indices.columns(); i++) { - int[] specifiedIndex = indices.getColumn(i).dup().data().asInt(); - ret.putScalar(i,getDouble(specifiedIndex)); - } - - return ret; - } - else { - List arrList = new ArrayList<>(); - - if(indices.isMatrix() || indices.isColumnVector()) { - for(int i = 0; i < indices.rows(); i++) { - if(i == 0) { - INDArray row = indices.getRow(i); - for(int j = 0; j < row.length(); j++) { - arrList.add(slice(row.getInt(j))); - } - } - else { - INDArray row = indices.slice(i); - for(int j = 0; j < row.length(); j++) { - INDArray put = arrList.get(j).slice(row.getInt(j)); - put = put.reshape(Longs.concat(new long[]{1}, put.shape())); - arrList.set(j,put); - } - } - } - } - else if(indices.isRowVector()) { - for(int i = 0; i < indices.length(); i++) { - arrList.add(slice(indices.getInt(i))); - } - } - return Nd4j.concat(0,arrList.toArray(new INDArray[arrList.size()])); - } - } - - @Override - public double[][] toDoubleMatrix() { - return new double[0][]; - } - - @Override - public double[] toDoubleVector() { - return new double[0]; - } - - @Override - public float[] toFloatVector() { - return new float[0]; - } - - @Override - public float[][] toFloatMatrix() { - return new float[0][]; - } - - @Override - public int[] toIntVector() { - return new int[0]; - } - - @Override - public long[] toLongVector() { - return new long[0]; - } - - @Override - public long[][] toLongMatrix() { - return new long[0][]; - } - - @Override - public int[][] toIntMatrix() { - return new int[0][]; - } - - @Override - public INDArray match(INDArray comp, Condition condition) { - return null; - } - - @Override - public INDArray match(Number comp, Condition condition) { - return null; - } - - @Override - public INDArray putWhereWithMask(INDArray mask, INDArray put) { - return null; - } - - @Override - public INDArray putWhereWithMask(INDArray mask, Number put) { - return null; - } - - @Override - public INDArray toDense() { - return null; - } - - @Override - public INDArray getWhere(INDArray comp, Condition condition) { - return null; - } - - @Override - public INDArray getWhere(Number comp, Condition condition) { - return null; - } - - @Override - public INDArray putWhere(INDArray comp, INDArray put, Condition condition) { - return null; - } - - @Override - public INDArray putWhere(Number comp, INDArray put, Condition condition) { - return null; - } - - @Override - public INDArray putWhere(Number comp, Number put, Condition condition) { - return null; - } - - @Override - public INDArray put(INDArray indices, INDArray element) { - INDArrayIndex[] realIndices = new INDArrayIndex[indices.rank()]; - for(int i = 0; i < realIndices.length; i++) { - realIndices[i] = new SpecifiedIndex(indices.slice(i).dup().data().asInt()); - } - return put(realIndices,element); - } - - @Override - public boolean isSparse() { - return isSparse; - } - - @Override - public long length() { - return length; - } - - @Override - public int nnz() { - // FIXME: int cast - return (int) length(); - } - - protected void init(long[] shape) { - - if (shape.length == 1) { - rows = 1; - columns = shape[0]; - } else if (this.shape().length == 2) { - rows = shape[0]; - columns = shape[1]; - } - rank = shape.length; - - } - - // Override methods from INDArray - // TODO: Most of them should be reimplemented for each format - - @Override - public String shapeInfoToString() { - return Shape.shapeToString(this); - } - - @Override - public DataBuffer shapeInfoDataBuffer() { - return shapeInformation; - } - - @Override - public DataBuffer sparseInfoDataBuffer() { - return sparseInformation; - } - - @Override - public LongBuffer shapeInfo() { - return null; - } - - @Override - public boolean isCompressed() { - return false; - } - - @Override - public void markAsCompressed(boolean reallyCompressed) { - - } - @Override - public int rank() { - return Shape.rank(shapeInformation); - } - - @Override - public int[] flags() { - return Shape.flags(sparseInformation); - } - - @Override - public int[] hiddenDimensions() { - return Shape.hiddenDimension(sparseInformation); - } - - @Override - public int[] sparseOffsets() { - return Shape.sparseOffsets(sparseInformation); - } - - @Override - public int stride(int dimension) { - int rank = Shape.rank(shapeInformation); - if (dimension < 0) - return strideOf().getInt(dimension + rank); - return strideOf().getInt(dimension); - } - - protected DataBuffer strideOf() { - if (stride == null) - stride = Shape.stride(shapeInfoDataBuffer()); - return stride; - } - - @Override - public int elementWiseStride() { - return 0; - } - - @Override - public double getDoubleUnsafe(long offset) { - return 0; - } - - @Override - public INDArray putScalarUnsafe(long offset, double value) { - return null; - } - - @Override - public long vectorsAlongDimension(int dimension) { - return 0; - } - - @Override - public INDArray vectorAlongDimension(int index, int dimension) { - return null; - } - - @Override - public long tensorsAlongDimension(int... dimension) { - return 0; - } - - @Override - public INDArray tensorAlongDimension(long index, int... dimension) { - return null; - } - - @Override - public INDArray cumsumi(int dimension) { - return null; - } - - @Override - public INDArray cumsum(int dimension) { - return null; - } - - @Override - public INDArray assign(INDArray arr) { - return null; - } - - @Override - public INDArray assignIf(INDArray arr, Condition condition) { - return null; - } - - @Override - public INDArray replaceWhere(INDArray arr, Condition condition) { - return null; - } - - @Override - public INDArray putScalar(long i, double value) { - return null; - } - - @Override - public INDArray putScalar(long i, float value) { - return null; - } - - @Override - public INDArray putScalar(long i, int value) { - return null; - } - - @Override - public INDArray putScalar(int[] i, double value) { - return null; - } - - @Override - public INDArray putScalar(long[] i, double value) { - return null; - } - - @Override - public INDArray putScalar(long[] i, float value) { - return null; - } - - @Override - public INDArray putScalar(long[] i, int value) { - return null; - } - - @Override - public INDArray isInfinite() { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray isNaN() { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray putScalar(long row, long col, double value) { - return null; - } - - @Override - public INDArray putScalar(long dim0, long dim1, long dim2, double value) { - return null; - } - - @Override - public INDArray putScalar(long dim0, long dim1, long dim2, long dim3, double value) { - return null; - } - - @Override - public INDArray lt(Number other) { - return null; - } - - @Override - public INDArray putScalar(int[] indexes, float value) { - return null; - } - - @Override - public INDArray putScalar(int[] indexes, int value) { - return null; - } - - @Override - public INDArray eps(Number other) { - return null; - } - - @Override - public INDArray eq(Number other) { - return null; - } - - @Override - public INDArray gt(Number other) { - return null; - } - - @Override - public INDArray gte(Number other) { - return null; - } - - @Override - public INDArray lte(Number other) { - return null; - } - - @Override - public INDArray lt(INDArray other) { - return null; - } - - @Override - public INDArray eps(INDArray other) { - return null; - } - - @Override - public INDArray neq(Number other) { - return null; - } - - @Override - public INDArray neq(INDArray other) { - return null; - } - - @Override - public INDArray eq(INDArray other) { - return null; - } - - @Override - public INDArray gt(INDArray other) { - return null; - } - - @Override - public INDArray neg() { - return null; - } - - @Override - public INDArray negi() { - return null; - } - - @Override - public INDArray rdiv(Number n) { - return null; - } - - @Override - public INDArray rdivi(Number n) { - return null; - } - - @Override - public INDArray rsub(Number n) { - return null; - } - - @Override - public INDArray rsubi(Number n) { - return null; - } - - @Override - public INDArray div(Number n) { - return null; - } - - @Override - public INDArray divi(Number n) { - return null; - } - - @Override - public INDArray mul(Number n) { - return null; - } - - @Override - public INDArray muli(Number n) { - return null; - } - - @Override - public INDArray sub(Number n) { - return null; - } - - @Override - public INDArray subi(Number n) { - return null; - } - - @Override - public INDArray add(Number n) { - return null; - } - - @Override - public INDArray addi(Number n) { - return null; - } - - @Override - public INDArray rdiv(Number n, INDArray result) { - return null; - } - - @Override - public INDArray rdivi(Number n, INDArray result) { - return null; - } - - @Override - public INDArray rsub(Number n, INDArray result) { - return null; - } - - @Override - public INDArray rsubi(Number n, INDArray result) { - return null; - } - - @Override - public INDArray div(Number n, INDArray result) { - return null; - } - - @Override - public INDArray divi(Number n, INDArray result) { - return null; - } - - @Override - public INDArray mul(Number n, INDArray result) { - return null; - } - - @Override - public INDArray muli(Number n, INDArray result) { - return null; - } - - @Override - public INDArray sub(Number n, INDArray result) { - return null; - } - - @Override - public INDArray subi(Number n, INDArray result) { - return null; - } - - @Override - public INDArray add(Number n, INDArray result) { - return null; - } - - @Override - public INDArray addi(Number n, INDArray result) { - return null; - } - - @Override - public INDArray get(INDArrayIndex... indexes) { - return null; - } - - @Override - public INDArray getColumns(int... columns) { - return null; - } - - @Override - public INDArray getRows(int... rows) { - return null; - } - - @Override - public INDArray rdiv(INDArray other) { - return null; - } - - @Override - public INDArray rdivi(INDArray other) { - return null; - } - - @Override - public INDArray rdiv(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray rdivi(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray rsub(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray rsub(INDArray other) { - return null; - } - - @Override - public INDArray rsubi(INDArray other) { - return null; - } - - @Override - public INDArray rsubi(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray assign(Number value) { - return null; - } - - @Override - public long linearIndex(long i) { - return 0; - } - - @Override - public void sliceVectors(List list) { - - } - - @Override - public INDArray putSlice(int slice, INDArray put) { - return null; - } - - @Override - public INDArray cond(Condition condition) { - return null; - } - - @Override - public INDArray repmat(int... shape) { - return null; - } - - @Override - public INDArray putRow(long row, INDArray toPut) { - return null; - } - - @Override - public INDArray putColumn(int column, INDArray toPut) { - return null; - } - - @Override - public INDArray getScalar(long row, long column) { - return null; - } - - @Override - public INDArray getScalar(long i) { - return null; - } - - @Override - public double squaredDistance(INDArray other) { - return 0; - } - - @Override - public double distance2(INDArray other) { - return 0; - } - - @Override - public double distance1(INDArray other) { - return 0; - } - - @Override - public INDArray put(INDArrayIndex[] indices, INDArray element) { - return null; - } - - @Override - public INDArray put(INDArrayIndex[] indices, Number element) { - return null; - } - - @Override - public INDArray put(int[] indices, INDArray element) { - return null; - } - - @Override - public INDArray put(int i, int j, INDArray element) { - return null; - } - - @Override - public INDArray put(int i, int j, Number element) { - return null; - } - - @Override - public INDArray put(int i, INDArray element) { - return null; - } - - @Override - public INDArray diviColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray divColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray diviRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray divRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray rdiviColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray rdivColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray rdiviRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray rdivRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray muliColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray mulColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray muliRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray mulRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray rsubiColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray rsubColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray rsubiRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray rsubRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray subiColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray subColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray subiRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray subRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray addiColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray addColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray addiRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray addRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray mmul(INDArray other) { - long[] shape = {rows(), other.columns()}; - INDArray result = createUninitialized(shape, 'f'); - if (result.isScalar()) - return Nd4j.scalar(Nd4j.getBlasWrapper().dot(this, other)); - return mmuli(other, result); - } - - @Override - public INDArray mmul(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray div(INDArray other) { - return null; - } - - @Override - public INDArray div(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray mul(INDArray other) { - return null; - } - - @Override - public INDArray mul(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray sub(INDArray other) { - return null; - } - - @Override - public INDArray sub(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray add(INDArray other) { - return null; - } - - @Override - public INDArray add(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray mmuli(INDArray other) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, INDArray result) { - LinAlgExceptions.assertMultiplies(this, other); - - - if (other.isScalar()) { - return muli(other.getDouble(0), result); - } - if (isScalar()) { - return other.muli(getDouble(0), result); - } - - /* check sizes and resize if necessary */ - - - - //We require that the result array is 'f' (fortran) order - // However, user might have called mmuli with a c order array for the result - // In which case, we need to allocate a temporary f order array, and later do an assign to the real result array - - boolean requiresTemp = result.ordering() == 'c'; - INDArray gemmResultArr; - if (requiresTemp) { - //Can use createUninitialized due to beta==0.0 parameter in gemm - gemmResultArr = Nd4j.createUninitialized(result.shape(), 'f'); - } else { - gemmResultArr = result; - } - - if (other.columns() == 1) { - Nd4j.getBlasWrapper().level2().gemv(ordering(), BlasBufferUtil.getCharForTranspose(other), 1.0, this, other, - 0.0, gemmResultArr); - } else { - //gemm doesn't support strides so vectors and views - //don't work - if (isView() && isVector()) { - return dup().mmuli(other, gemmResultArr); - } - - Nd4j.getBlasWrapper().level3().gemm(ordering(), BlasBufferUtil.getCharForTranspose(other), - BlasBufferUtil.getCharForTranspose(gemmResultArr), 1.0, this, other, 0.0, gemmResultArr); - } - - if (requiresTemp) { - result.assign(gemmResultArr); - } - - return result; - } - - @Override - public INDArray divi(INDArray other) { - return null; - } - - @Override - public INDArray divi(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray muli(INDArray other) { - return null; - } - - @Override - public INDArray muli(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray subi(INDArray other) { - return null; - } - - @Override - public INDArray subi(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray addi(INDArray other) { - return null; - } - - @Override - public INDArray addi(INDArray other, INDArray result) { - return null; - } - - @Override - public INDArray normmax(int... dimension) { - return null; - } - - @Override - public Number normmaxNumber() { - return null; - } - - @Override - public INDArray norm2(int... dimension) { - return null; - } - - @Override - public Number norm2Number() { - return null; - } - - @Override - public INDArray norm1(int... dimension) { - return null; - } - - @Override - public Number norm1Number() { - return null; - } - - @Override - public INDArray std(int... dimension) { - return null; - } - - @Override - public Number stdNumber() { - return null; - } - - @Override - public INDArray std(boolean biasCorrected, int... dimension) { - return null; - } - - @Override - public Number stdNumber(boolean biasCorrected) { - return null; - } - - @Override - public INDArray prod(int... dimension) { - return null; - } - - @Override - public Number prodNumber() { - return null; - } - - @Override - public INDArray mean(int... dimension) { - return null; - } - - @Override - public Number meanNumber() { - return null; - } - - @Override - public INDArray var(int... dimension) { - return null; - } - - @Override - public INDArray var(boolean biasCorrected, int... dimension) { - return null; - } - - @Override - public Number varNumber() { - return null; - } - - @Override - public INDArray max(int... dimension) { - return null; - } - - @Override - public Number maxNumber() { - return null; - } - - @Override - public INDArray min(int... dimension) { - return null; - } - - @Override - public Number minNumber() { - return null; - } - - @Override - public INDArray sum(int... dimension) { - return null; - } - - @Override - public INDArray sum(boolean keepDims, int... dimension){ - return null; - } - - @Override - public Number sumNumber() { - return null; - } - - @Override - public INDArray normmax(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray norm2(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray norm1(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray std(boolean biasCorrected, boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray prod(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray mean(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray mean(INDArray result, boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray max(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray min(boolean keepDims, int... dimension) { - return null; - } - - @Override - public INDArray sum(INDArray result, boolean keepDims, int... dimension) { - return null; - } - - @Override - public void setShapeAndStride(int[] shape, int[] stride) { - } - - @Override - public void setOrder(char order) { - } - - @Override - public Number getNumber(long index) { - return null; - } - - @Override - public Number getNumber(long... indices) { - return null; - } - - @Override - public INDArray getScalar(int... indices) { - return null; - } - - @Override - public INDArray getScalar(long... indices) { - return null; - } - - @Override - public float getFloat(long... indices) { - return 0; - } - - @Override - public double getDouble(long... indices) { - return 0; - } - - @Override - public int getInt(int... indices) { - return 0; - } - - @Override - public long getLong(long... indices) { - return 0; - } - - @Override - public double getDouble(int... indices) { - return 0; - } - - @Override - public float getFloat(int... indices) { - return 0; - } - - @Override - public double getDouble(long i) { - return 0; - } - - @Override - public double getDouble(long i, long j) { - return 0; - } - - @Override - public float getFloat(long i) { - return 0; - } - - @Override - public float getFloat(long i, long j) { - return 0; - } - - @Override - public INDArray dup() { - return null; - } - - @Override - public INDArray dup(char order) { - return null; - } - - @Override - public INDArray ravel() { - return null; - } - - @Override - public INDArray ravel(char order) { - return null; - } - - @Override - public void setData(DataBuffer data) { - - } - - @Override - public long slices() { - return 0; - } - - @Override - public int getTrailingOnes() { - return 0; - } - - @Override - public int getLeadingOnes() { - return 0; - } - - @Override - public INDArray slice(long i, int dimension) { - return null; - } - - @Override - public INDArray slice(long i) { - return null; - } - - @Override - public long offset() { - return 0; - } - - @Override - public long originalOffset() { - return 0; - } - - @Override - public INDArray reshape(char order, long... newShape) { - return null; - } - - @Override - public INDArray reshape(char order, int rows, int columns) { - return null; - } - - @Override - public INDArray reshape(long... newShape) { - return null; - } - - @Override - public INDArray reshape(long rows, long columns) { - return null; - } - - @Override - public INDArray transpose() { - return null; - } - - @Override - public INDArray transposei() { - return null; - } - - @Override - public INDArray swapAxes(int dimension, int with) { - return null; - } - - @Override - public INDArray permute(int... rearrange) { - return null; - } - - @Override - public INDArray permutei(int... rearrange) { - return null; - } - - @Override - public INDArray dimShuffle(Object[] rearrange, int[] newOrder, boolean[] broadCastable) { - return null; - } - - @Override - public INDArray broadcast(INDArray result) { - return null; - } - - @Override - public INDArray dimShuffle(Object[] rearrange, long[] newOrder, boolean[] broadCastable) { - return null; - } - - @Override - public INDArray getColumn(long i) { - return null; - } - - @Override - public INDArray getColumn(long i, boolean keepDim) { - return null; - } - - @Override - public INDArray getRow(long i) { - return null; - } - - @Override - public INDArray getRow(long i, boolean keepDim) { - return null; - } - - @Override - public int columns() { - return (int) columns; - } - - @Override - public int rows() { - return (int) rows; - } - - /** - * Checks whether the matrix is a vector. - */ - @Override - public boolean isVector() { - return isRowVector() || isColumnVector(); - } - - @Override - public boolean isVectorOrScalar() { - return isVector() || isScalar(); - } - - @Override - public boolean isSquare() { - - return isMatrix() && rows() == columns(); - } - - @Override - public boolean isRowVector() { - return rank == 2 && rows == 1; - } - - @Override - public boolean isColumnVector() { - return rank == 2 && columns == 1; - } - - @Override - public boolean isMatrix() { - if (isMatrix != null) - return isMatrix; - isMatrix = (rank == 2 && (size(0) != 1 && size(1) != 1)); - return isMatrix; - } - - @Override - public boolean isScalar() { - if (isScalar != null) - return isScalar; - if (Shape.rank(shapeInformation) > 2) { - isScalar = false; - } else if (Shape.rank(shapeInformation) == 1) { - isScalar = shapeOf().getInt(0) == 1; - } else if (Shape.rank(shapeInformation) == 2) { - isScalar = shapeOf().getInt(0) == 1 && shapeOf().getInt(1) == 1; - } - - else - isScalar = false; - - return isScalar; - } - - @Override - public char ordering() { - return 'c'; - } - - @Override - public long[] shape() { - return Shape.shape(javaShapeInformation); - } - - protected DataBuffer shapeOf() { - if (shape == null) - shape = Shape.shapeOf(shapeInfoDataBuffer()); - return shape; - } - - @Override - public long[] stride() { - return Shape.stride(javaShapeInformation); - } - - @Override - public long size(int dimension) { - if (isScalar()) { - if (dimension == 0 || dimension == 1 || dimension < 0) - return (int) length; - else - throw new IllegalArgumentException("Illegal dimension for scalar " + dimension); - } - - if (dimension < 0) { - return shapeOf().getInt(dimension + Shape.rank(shapeInformation)); - } - - if (dimension >= rank()) - throw new IllegalArgumentException("Invalid size: cannot get size of dimension " + dimension + " for rank " - + rank() + " NDArray (array shape: " + Arrays.toString(this.shape()) + ")"); - - - return shapeOf().getInt(dimension); - } - - protected void setShapeInformation(Pair shapeInfo) { - this.shapeInformation = shapeInfo.getFirst(); - this.javaShapeInformation = shapeInfo.getSecond(); - } - - @Override - public INDArray broadcast(long... shape) { - return null; - } - - @Override - public Object element() { - return null; - } - - @Override - public boolean equals(Object o) { - return equalsWithEps(o, Nd4j.EPS_THRESHOLD); - } - - @Override - public boolean equalShapes(@NonNull INDArray other){ - if(rank() != other.rank()) - return false; - for( int i=0; i 100) - throw new ND4JIllegalStateException("Percentile value should be in 0...100 range"); - - if (isScalar()) - return this.getDouble(0); - - INDArray sorted = Nd4j.sort(this.dup(this.ordering()), true); - - return getPercentile(quantile, sorted); - } - - @Override - public Number medianNumber() { - return percentileNumber(50); - } - - @Override - public INDArray median(int... dimension) { - return percentile(50, dimension); - } - - protected double getPercentile(Number quantile, INDArray sorted) { - if (quantile.intValue() == 0) - return sorted.getDouble(0); - else if (quantile.intValue() == 100) - return sorted.getDouble(sorted.length() - 1); - - double pos = (quantile.doubleValue() / 100.0) * (double) (sorted.length() + 1); - - double fposition = FastMath.floor(pos); - int position = (int) fposition; - - double diff = pos - fposition; - - double lower = sorted.getDouble(position - 1); - double upper = sorted.getDouble(position); - - return lower + diff * (upper - lower); - } - - @Override - public INDArray percentile(Number quantile, int... dimension) { - if (quantile.doubleValue() < 0 || quantile.doubleValue() > 100) - throw new ND4JIllegalStateException("Percentile value should be in 0...100 range"); - - if (isScalar()) - return Nd4j.scalar(this.getDouble(0)); - - INDArray sorted = Nd4j.getNDArrayFactory().sort(this.dup(this.ordering()), false, dimension); - - // there's no practical sense doing this on GPU, stride will be just size of TAD. - INDArray ret = Nd4j.createUninitialized(sorted.tensorsAlongDimension(dimension)); - for (int i = 0; i < ret.length(); i++) { - ret.putScalar(i, getPercentile(quantile, sorted.tensorAlongDimension(i, dimension))); - } - - return ret; - - } - - @Override - public long[] shapeInfoJava() { - return javaShapeInformation; - } - - @Override - public DataType dataType() { - return data().dataType(); - } - - @Override - public boolean all() { - return false; - } - - @Override - public boolean any() { - return false; - } - - @Override - public boolean none() { - return false; - } - - @Override - public INDArray like() { - throw new UnsupportedOperationException("Not yet implemented"); - } - - @Override - public INDArray ulike() { - throw new UnsupportedOperationException("Not yet implemented"); - } - - @Override - public String toString(NDArrayStrings options){ - return "SPARSE ARRAY, TOSTRING NOT SUPPORTED"; - } - - @Override - public String toString(long maxElements, boolean forceSummarize, int decimalPlaces){ - return toString(new NDArrayStrings(maxElements, forceSummarize, decimalPlaces)); - } - - @Override - public String toStringFull(){ - return toString(Long.MAX_VALUE, false, dataType().precision()); - } - - @Override - public String toString(){ - return toString(new NDArrayStrings()); - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java deleted file mode 100644 index b50200dbb..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java +++ /dev/null @@ -1,1184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -import org.nd4j.shade.guava.primitives.Doubles; -import org.nd4j.shade.guava.primitives.Ints; -import org.nd4j.shade.guava.primitives.Longs; -import com.google.flatbuffers.FlatBufferBuilder; -import net.ericaro.neoitertools.Generator; -import org.nd4j.linalg.api.blas.params.MMulTranspose; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ops.executioner.OpExecutioner; -import org.nd4j.linalg.api.shape.LongShapeDescriptor; -import org.nd4j.linalg.api.shape.Shape; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.indexing.*; -import org.nd4j.linalg.profiler.OpProfiler; -import org.nd4j.linalg.util.ArrayUtil; -import org.nd4j.linalg.util.LongUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.NoSuchElementException; - -import static org.nd4j.base.Preconditions.checkArgument; -import static org.nd4j.base.Preconditions.checkNotNull; - -/** - * @author Audrey Loeffel - */ - -/* -* TODO : -* - Implement the INDArray methods -* - Sort the databuffers -* - Check at the creation if there are any 0 values and remove them -* - add indexesOrdering in constructor -* - BaseSparseNDArray should extend from BaseNDArray : remove the duplicate methods -* */ -public class BaseSparseNDArrayCOO extends BaseSparseNDArray { - protected static final SparseFormat format = SparseFormat.COO; - protected transient volatile DataBuffer values; - protected transient volatile DataBuffer indices; - protected transient volatile boolean isSorted = false; - - public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, long[] shape) { - checkArgument(values.length() * shape.length == indices.length()); - - this.values = values; - this.indices = indices; - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.length = values.length(); - int[] flags = new int[rank()]; - long[] sparseOffsets = new long[rank()]; - int[] hiddenDimension = new int[] {-1}; - this.sparseInformation = Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets, - hiddenDimension, rank()); - - } - - public BaseSparseNDArrayCOO(double[] values, long[][] indices, long[] shape) { - this.indices = createIndiceBuffer(indices, shape); - this.values = createValueBuffer(values); - length = values.length; - - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.sparseInformation = createSparseInformationBuffer(rank()); - checkBufferCoherence(); - } - - public BaseSparseNDArrayCOO(float[] values, long[][] indices, long[] shape) { - this.indices = createIndiceBuffer(indices, shape); - this.values = createValueBuffer(values); - length = values.length; - - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.sparseInformation = createSparseInformationBuffer(rank()); - checkBufferCoherence(); - } - - public BaseSparseNDArrayCOO(double[] values, int[][] indices, long[] shape) { - this.indices = createIndiceBuffer(indices, shape); - this.values = createValueBuffer(values); - length = values.length; - - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.sparseInformation = createSparseInformationBuffer(rank()); - checkBufferCoherence(); - } - - public BaseSparseNDArrayCOO(float[] values, int[][] indices, long[] shape) { - this.indices = createIndiceBuffer(indices, shape); - this.values = createValueBuffer(values); - length = values.length; - - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.sparseInformation = createSparseInformationBuffer(rank()); - checkBufferCoherence(); - } - - - public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - this.values = Nd4j.createBuffer(values, 0, values.length()); - this.indices = indices; - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.sparseInformation = sparseInformation; - this.length = countNNZ(); - - } - - public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, - int[] hiddenDimensions, int underlyingRank, long[] shape) { - this(values, indices, Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets, - hiddenDimensions, underlyingRank), shape); - } - - - /** - * Check that the length of indices and values are coherent and matches the rank of the matrix. - */ - protected void checkBufferCoherence(){ - if (values.length() < length){ - throw new IllegalStateException("nnz is larger than capacity of buffers"); - } - - if (values.length() * rank() != indices.length()){ - throw new IllegalArgumentException("Sizes of values, indices and shape are incoherent."); - } - } - - /** - * Create a SparseInfo databuffer given rank if of the sparse matrix. - * @param rank - * @return - */ - protected static DataBuffer createSparseInformationBuffer(int rank){ - int[] flags = new int[rank]; - long[] sparseOffsets = new long[rank]; - int[] hiddenDimension = new int[] {-1}; - return Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets, - hiddenDimension, rank); - } - - - /** - * Create a DataBuffer for values of given array of values. - * @param values - * @return - */ - protected static DataBuffer createValueBuffer(float[] values) { - checkNotNull(values); - if (values.length == 0){ - return Nd4j.createBuffer(1); - } - return Nd4j.createBuffer(values); - } - - - /** - * Create a DataBuffer for values of given array of values. - * @param values - * @return - */ - protected static DataBuffer createValueBuffer(double[] values) { - checkNotNull(values); - if (values.length == 0){ - return Nd4j.createBuffer(1); - } - return Nd4j.createBuffer(values); - } - - - - /** - * Create a DataBuffer for indices of given arrays of indices. - * @param indices - * @param shape - * @return - */ - protected static DataBuffer createIndiceBuffer(long[][] indices, long[] shape){ - checkNotNull(indices); - checkNotNull(shape); - if(indices.length == 0){ - return Nd4j.getDataBufferFactory().createLong(shape.length); - } - - if (indices.length == shape.length) { - return Nd4j.createBuffer(ArrayUtil.flattenF(indices)); - } - - return Nd4j.createBuffer(ArrayUtil.flatten(indices)); - } - - /** - * Create a DataBuffer for indices of given arrays of indices. - * @param indices - * @param shape - * @return - */ - protected static DataBuffer createIndiceBuffer(int[][] indices, long[] shape){ - checkNotNull(indices); - checkNotNull(shape); - if(indices.length == 0){ - return Nd4j.getDataBufferFactory().createLong(shape.length); - } - - if (indices.length == shape.length) { - return Nd4j.createBuffer(ArrayUtil.toLongArray(ArrayUtil.flattenF(indices))); - } - - return Nd4j.createBuffer(ArrayUtil.toLongArray(ArrayUtil.flatten(indices))); - } - - @Override - public int toFlatArray(FlatBufferBuilder builder) { - throw new UnsupportedOperationException(); - } - - - - /** - * Count the number of value that are included in the ndarray (view) according to the sparse offsets and the shape - * @return nnz - * */ - public long countNNZ() { - long count = 0; - - for (int i = 0; i < values.length(); i++) { - int[] idx = getUnderlyingIndicesOf(i).asInt(); - boolean isIn = true; - int idxNotFixed = 0; - for (int dim = 0; dim < idx.length; dim++) { - - if (flags()[dim] == 1) { - if (sparseOffsets()[dim] != idx[dim]) { - isIn = false; - break; - } - } else { - int lowerBound = sparseOffsets()[dim]; - long upperBound = sparseOffsets()[dim] + shape()[idxNotFixed]; - if (!(idx[dim] >= lowerBound && idx[dim] < upperBound)) { - isIn = false; - break; - } - idxNotFixed++; - } - } - count = isIn ? count + 1 : count; - } - return count; - } - - @Override - public INDArray assign(final INDArray arr) { - sort(); - // TODO - set via native op - return this; - } - - /** - * Sort the indexes and the values buffers - * */ - public void sort() { - if (!isSorted) { - Nd4j.sparseFactory().sortCooIndices(this); - isSorted = true; - } - } - - /** - * Translate the view index to the corresponding index of the original ndarray - * @param virtualIndexes the view indexes - * @return the original indexes - * */ - public long[] translateToPhysical(long[] virtualIndexes) { - - long[] physicalIndexes = new long[underlyingRank()]; - int idxPhy = 0; - int hidden = 0; - - for (int idxVir = 0; idxVir < virtualIndexes.length; idxVir++) { - if (hidden < getNumHiddenDimension() && hiddenDimensions()[hidden] == idxVir) { - hidden++; - } else { - while (idxPhy < underlyingRank() && isDimensionFixed(idxPhy)) { - physicalIndexes[idxPhy] = sparseOffsets()[idxPhy]; - idxPhy++; - } - if (idxPhy < underlyingRank() && !isDimensionFixed(idxPhy)) { - physicalIndexes[idxPhy] = sparseOffsets()[idxPhy] + virtualIndexes[idxVir]; - idxPhy++; - } - } - } - return physicalIndexes; - } - - public int[] translateToPhysical(int[] virtualIndexes) { - - int[] physicalIndexes = new int[underlyingRank()]; - int idxPhy = 0; - int hidden = 0; - - for (int idxVir = 0; idxVir < virtualIndexes.length; idxVir++) { - if (hidden < getNumHiddenDimension() && hiddenDimensions()[hidden] == idxVir) { - hidden++; - } else { - while (idxPhy < underlyingRank() && isDimensionFixed(idxPhy)) { - physicalIndexes[idxPhy] = sparseOffsets()[idxPhy]; - idxPhy++; - } - if (idxPhy < underlyingRank() && !isDimensionFixed(idxPhy)) { - physicalIndexes[idxPhy] = sparseOffsets()[idxPhy] + virtualIndexes[idxVir]; - idxPhy++; - } - } - } - return physicalIndexes; - } - - /** - * Return if the dimension in argument is a fixed dimension. - * */ - public boolean isDimensionFixed(int i) { - return flags()[i] == 1; - } - - - @Override - public INDArray putScalar(long i, double value) { - if (i < 0) - i += rank(); - if (isScalar()) { - if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.DISABLED && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.SCOPE_PANIC) - OpProfiler.getInstance().processScalarCall(); - - addOrUpdate(new long[] {0, 0}, value); - return this; - } - if (isRowVector()) { - addOrUpdate(new long[] {0, i}, value); - return this; - } else if (isColumnVector()) { - addOrUpdate(new long[] {i, 0}, value); - return this; - } - long[] indexes = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); - return putScalar(indexes, value); - } - - @Override - public INDArray putScalar(long i, float value) { - return putScalar(i, (double) value); //todo - move in baseSparse? - } - - @Override - public INDArray putScalar(long i, int value) { - return putScalar(i, (double) value); //todo - } - - @Override - public INDArray putScalar(int[] indexes, double value) { - return putScalar(ArrayUtil.toLongArray(indexes), value); - } - - @Override - public INDArray putScalar(long[] indexes, double value) { - for (int i = 0; i < indexes.length; i++) { - if (indexes[i] < 0) - indexes[i] += rank(); - } - - if (indexes.length == 1) { - return putScalar(indexes[0], value); - } - if (indexes.length != rank) { - throw new IllegalStateException( - "Cannot use putScalar with indexes length " + indexes.length + " on rank " + rank); - } - addOrUpdate(indexes, value); - return this; - } - - @Override - public INDArray putScalar(long[] i, float value) { - return null; - } - - @Override - public INDArray putScalar(long[] i, int value) { - return null; - } - - @Override - public INDArray putScalar(long row, long col, double value) { - return putScalar(new long[] {row, col}, value); - } - - @Override - public INDArray putScalar(long dim0, long dim1, long dim2, double value) { - return putScalar(new long[] {dim0, dim1, dim2}, value); - } - - @Override - public INDArray putScalar(long dim0, long dim1, long dim2, long dim3, double value) { - return putScalar(new long[] {dim0, dim1, dim2, dim3}, value); - } - - @Override - public INDArray putRow(long row, INDArray toPut) { - if (isRowVector() && toPut.isVector()) { - return assign(toPut); - } - return put(new INDArrayIndex[] {NDArrayIndex.point(row), NDArrayIndex.all()}, toPut); - } - - @Override - public INDArray putColumn(int column, INDArray toPut) { - if (isColumnVector() && toPut.isVector()) { - return assign(toPut); - } - return put(new INDArrayIndex[] {NDArrayIndex.all(), NDArrayIndex.point(column)}, toPut); - } - - @Override - public INDArray put(INDArrayIndex[] indices, INDArray element) { - get(indices).assign(element); - return this; - } - - @Override - public INDArray put(INDArrayIndex[] indices, Number element) { - INDArray get = get(indices); - for (int i = 0; i < get.length(); i++) - get.putScalar(i, element.doubleValue()); - return this; - } - - @Override - public INDArray put(int[] indexes, INDArray element) { - - if (!element.isScalar()) - throw new IllegalArgumentException("Unable to insert anything but a scalar"); - if (indexes.length != rank) - throw new IllegalStateException( - "Cannot use putScalar with indexes length " + indexes.length + " on rank " + rank); - - addOrUpdate(ArrayUtil.toLongArray(indexes), element.getDouble(0)); - return this; - } - - @Override - public INDArray put(int i, int j, INDArray element) { // TODO in base ? - return put(new int[] {i, j}, element); - } - - @Override - public INDArray put(int i, int j, Number element) { // TODO in base - return putScalar(new int[] {i, j}, element.doubleValue()); - } - - @Override - public INDArray put(int i, INDArray element) { // TODO remove and use basendarray method - if (!element.isScalar()) - throw new IllegalArgumentException("Element must be a scalar"); - return putScalar(i, element.getDouble(0)); - } - - /** - * Add a new element in the ndarray or update the value if there is already a non-null element at this position - * @param indexes the indexes of the element to be added - * @param value the value of the element to be added - * */ - public void addOrUpdate(long[] indexes, double value) { - - long[] physicalIndexes = isView() ? translateToPhysical(indexes) : indexes; - - for (int i = 0; i < length; i++) { - long[] idx = getUnderlyingIndicesOf(i).asLong(); - if (Arrays.equals(idx, physicalIndexes)) { - // There is already a non-null value at this index - // -> update the current value, the sort is maintained - if (value == 0) { - removeEntry(i); - length--; - } else { - values.put(i, value); - length++; - } - return; - } - } - - // If the value is 0 and there is no existing non-null value at the given index - if (value == 0) { - return; - } - - /* It's a new non-null element. We add the value and the indexes at the end of their respective databuffers. - * The buffers are no longer sorted ! - * /!\ We need to reallocate the buffers if they are full - */ - while (!canInsert(values, 1)) { - long size = (long) Math.ceil((values.capacity() * THRESHOLD_MEMORY_ALLOCATION)); - values.reallocate(size); - } - values.put(length, value); - while (!canInsert(indices, physicalIndexes.length)) { - long size = (long) Math.ceil((indices.capacity() * THRESHOLD_MEMORY_ALLOCATION)); - indices.reallocate(size); - } - for (int i = 0; i < physicalIndexes.length; i++) { - indices.put(length * rank() + i, physicalIndexes[i]); - } - length++; - isSorted = false; - } - - /** - * Return if there is enough allocated memory space to add data of a given length in the databuffer - * @param buffer a databuffer in which we want to add data - * @param length the length of the data - * @return a boolean if the insertion is possible - * */ - public boolean canInsert(DataBuffer buffer, int length) { - return buffer.capacity() - buffer.length() >= length; - } - - public DataBuffer shiftLeft(DataBuffer buffer, int from, int offset, long datalength) { - for (int i = from; i < datalength; i++) { - buffer.put(i - offset, buffer.getDouble(i)); - } - return buffer; - } - - /** - * Remove an element of the ndarray - * @param idx the index of the element to be removed - * @return the ndarray - * */ - public INDArray removeEntry(int idx) { - values = shiftLeft(values, idx + 1, 1, length()); - indices = shiftLeft(indices, (int) (idx * shape.length() + shape.length()), (int) shape.length(), - indices.length()); - return this; - } - - @Override - public INDArray get(INDArrayIndex... indexes) { - - sort(); - - if (indexes.length == 1 && indexes[0] instanceof NDArrayIndexAll || (indexes.length == 2 && (isRowVector() - && indexes[0] instanceof PointIndex && indexes[0].offset() == 0 - && indexes[1] instanceof NDArrayIndexAll - || isColumnVector() && indexes[1] instanceof PointIndex && indexes[0].offset() == 0 - && indexes[0] instanceof NDArrayIndexAll))) - return this; - - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public INDArray assign(boolean value) { - return assign(value ? 1 : 0); - } - - @Override - public INDArray repeat(int dimension, long... repeats) { - return null; - } - - - public int[] filterOutFixedDimensions(int[] flags, List idx) { - checkArgument(flags.length == idx.size()); - int lastIdx = idx.size() - 1; - for (int i = lastIdx; i >= 0; i--) { - if (flags[i] == 1) { - idx.remove(i); - } - } - return Ints.toArray(idx); - } - - /** - * Return the index of the value corresponding to the indexes - * @param indexes - * @return index of the value - * */ - public int reverseIndexes(int... indexes) { - long[] idx = translateToPhysical(ArrayUtil.toLongArray(indexes)); - sort(); - - // FIXME: int cast - return indexesBinarySearch(0, (int) length(), ArrayUtil.toInts(idx)); - } - - /** - * Return the position of the idx array into the indexes buffer between the lower and upper bound. - * @param idx a set of coordinates - * @param lowerBound the lower bound of the position - * @param upperBound the upper bound of the position - * @return the position of the idx array into the indexes buffers, which corresponds to the position of - * the corresponding value in the values data. - * */ - public int indexesBinarySearch(int lowerBound, int upperBound, int[] idx) { - int min = lowerBound; - int max = upperBound; - - int mid = (max + min) / 2; - int[] midIdx = getUnderlyingIndicesOf(mid).asInt(); - if (Arrays.equals(idx, midIdx)) { - return mid; - } - if (ArrayUtil.lessThan(idx, midIdx)) { - max = mid; - } - if (ArrayUtil.greaterThan(idx, midIdx)) { - min = mid; - } - if (min == max) { - return -1; - } - return indexesBinarySearch(min, max, idx); - } - - @Override - public INDArray getScalar(int... indices) { - return super.getScalar(indices); - } - - @Override - public INDArray getScalar(long... indices) { - return null; - } - - @Override - public int getInt(int... indices) { - return super.getInt(indices); - } - - @Override - public long getLong(long index) { - return 0; - } - - @Override - public double getDouble(int... indices) { - int valIdx = reverseIndexes(indices); - if (valIdx == -1) { - return 0; - } else { - return values.getDouble(valIdx); - } - } - - @Override - public double getDouble(long... indices) { - return 0; - } - - @Override - public float getFloat(int... indices) { - return (float) getDouble(indices); - } - - @Override - public float getFloat(long... indices) { - return 0; - } - - @Override - public double getDouble(long i) { - if (i >= length()) { - throw new IllegalArgumentException("Unable to get linear index >= " + length()); - } - - if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.DISABLED && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.SCOPE_PANIC) - OpProfiler.getInstance().processScalarCall(); - - if (i == 0) - return data().getDouble(i); - - long[] dimensions = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); - Shape.assertShapeLessThan(dimensions, shape()); - return getDouble(dimensions); - } - - @Override - public double getDouble(long i, long j) { - return getDouble(new long[] {i, j}); - } - - @Override - public float getFloat(long i) { - return (float) getDouble(i); - } - - @Override - public float getFloat(long i, long j) { - return (float) getDouble(i, j); - } - - @Override - public INDArray reshape(char order, int... newShape) { - return null; - } - - @Override - public INDArray reshape(char order, boolean enforceView, long... newShape) { - return null; - } - - @Override - public INDArray reshape(int[] shape) { - return null; - } - - @Override - public LongShapeDescriptor shapeDescriptor() { - throw new UnsupportedOperationException(); - } - - public SparseFormat getFormat() { - return format; - } - - @Override - public int underlyingRank() { - return Shape.underlyingRank(sparseInformation); - } - - @Override - public DataBuffer data() { - return values; - } - - /** - * Return the indices buffer - * @return indices - * */ - public DataBuffer getUnderlyingIndices() { - return indices; - } - - /** - * Return a copy of the indices included in the view. - * /!\ Change this DataBuffer won't change the ndarray! - * @return an array containing the virtual indexes of the values (think about views). - * */ - public DataBuffer getIncludedIndices() { - - if (isScalar()) { - return Nd4j.createBuffer(new int[] {0, 0}); - } - - List ind = new ArrayList<>(); - - for (int i = 0; i < values.length(); i++) { - boolean isIn = true; - int idxNotFixed = 0; - int[] idx = getUnderlyingIndicesOf(i).asInt(); // TODO change for getIndicesOf(i) - - for (int dim = 0; dim < idx.length; dim++) { - if (flags()[dim] == 1) { - if (sparseOffsets()[dim] != idx[dim]) { - isIn = false; - break; - } - } else { - int lowerBound = sparseOffsets()[dim]; - long upperBound = sparseOffsets()[dim] + shape()[idxNotFixed]; - if (!(idx[dim] >= lowerBound && idx[dim] < upperBound)) { - isIn = false; - break; - } - idxNotFixed++; - } - } - if (isIn) { - int notFixedDim = 0; - for (int dim = 0; dim < idx.length; dim++) { - if (flags()[dim] == 0) { - if (shape()[notFixedDim] == 1) { - ind.add(0); - notFixedDim++; - } else { - ind.add(idx[dim] - sparseOffsets()[dim]); - } - } - } - } - } - return Nd4j.createBuffer(Ints.toArray(ind)); - } - - /** - * Return the values buffer - * @return values - * */ - public DataBuffer getUnderlyingValues() { - return values; - } - - /** - * Return a copy of the values included in the array. - * /!\ Change this DataBuffer won't change the ndarray! - * @return an array containing the values - * */ - public DataBuffer getIncludedValues() { - List val = new ArrayList<>(); - - for (int i = 0; i < values.length(); i++) { - boolean isIn = true; - int idxNotFixed = 0; - int[] idx = getUnderlyingIndicesOf(i).asInt(); - for (int dim = 0; dim < idx.length; dim++) { - if (flags()[dim] == 1) { - if (sparseOffsets()[dim] != idx[dim]) { - isIn = false; - break; - } - } else { - int lowerBound = sparseOffsets()[dim]; - long upperBound = sparseOffsets()[dim] + shape()[idxNotFixed]; - if (!(idx[dim] >= lowerBound && idx[dim] < upperBound)) { - isIn = false; - break; - } - idxNotFixed++; - } - } - if (isIn) { - val.add(values.getDouble(i)); - } - } - return Nd4j.createBuffer(Doubles.toArray(val)); - } - - @Override - public DataBuffer getVectorCoordinates() { - int idx; - if (isRowVector()) { - idx = 1; - } else if (isColumnVector()) { - idx = 0; - } else { - throw new UnsupportedOperationException(); - } - - // FIXME: int cast - int[] temp = new int[(int) length()]; - for (int i = 0; i < length(); i++) { - temp[i] = getUnderlyingIndicesOf(i).getInt(idx); - } - return Nd4j.createBuffer(temp); - } - - @Override - public INDArray toDense() { - // TODO support view conversion - INDArray result = Nd4j.zeros(shape()); - - switch (data().dataType()) { - case DOUBLE: - for (int i = 0; i < length; i++) { - int[] idx = getUnderlyingIndicesOf(i).asInt(); - double value = values.getDouble(i); - result.putScalar(idx, value); - } - break; - case FLOAT: - for (int i = 0; i < length; i++) { - int[] idx = getUnderlyingIndicesOf(i).asInt(); - float value = values.getFloat(i); - result.putScalar(idx, value); - } - break; - default: - throw new UnsupportedOperationException(); - } - return result; - } - - @Override - public DataBuffer shapeInfoDataBuffer() { - return shapeInformation; - } - - /** - * Compute the sparse offsets of the view we are getting, for each dimension according to the original ndarray - * @param offset the offset of the view - * @return an int array containing the sparse offsets - * */ - private long[] createSparseOffsets(long offset) { - - // resolve the offsets in the view dimension - int underlyingRank = sparseOffsets().length; - long[] newOffsets = new long[rank()]; - List shapeList = Longs.asList(shape()); - int penultimate = rank() - 1; - for (int i = 0; i < penultimate; i++) { - long prod = ArrayUtil.prodLong(shapeList.subList(i + 1, rank())); - newOffsets[i] = offset / prod; - offset = offset - newOffsets[i] * prod; - } - newOffsets[rank() - 1] = offset % shape()[rank() - 1]; - - // Merge the offsets with the original sparseOffsets - long[] finalOffsets = new long[underlyingRank]; - int dimNotFixed = 0; - for (int dim = 0; dim < underlyingRank; dim++) { - if (flags()[dim] == 1) { - finalOffsets[dim] = sparseOffsets()[dim]; - } else { - finalOffsets[dim] = newOffsets[dimNotFixed] + sparseOffsets()[dim]; - dimNotFixed++; - } - } - return finalOffsets; - } - - private int[] createHiddenDimensions(int[] newAxis) { - if (newAxis == null || newAxis.length == 0) { - return hiddenDimensions(); - } - if (getNumHiddenDimension() == 0) { - return newAxis; - } - int size = newAxis.length + hiddenDimensions().length; - int[] newHiddenDim = new int[size]; - int newDim = 0; - int actualArrayIdx = 0; - for (int oldDim = 0; oldDim < getNumHiddenDimension(); oldDim++) { - while ((newDim < newAxis.length) && (oldDim >=getNumHiddenDimension() || newAxis[newDim] <= hiddenDimensions()[oldDim])) { - newHiddenDim[actualArrayIdx] = newAxis[newDim] + oldDim; - actualArrayIdx++; - newDim++; - } - newHiddenDim[actualArrayIdx] = hiddenDimensions()[oldDim] + newDim; - actualArrayIdx++; - } - return newHiddenDim; - } - - /** - * Adjust the flags array according on the current context: - * - In case of a vector or a scalar, we need to keep flags to 0 - * - There must always be at least 2 non-flags dimensions - * - We must keep the flags dimensions of the original array - * - * @param viewFlags the Fixed array calculate within the view - * @param newShape the shape of the view - * */ - private int[] updateFlags(int[] viewFlags, long[] newShape) { - // Check if flags is well-formed - int count = 0; - for (int i = 0; i < viewFlags.length; i++) { - if (viewFlags[i] == 0) { - count++; - } - } - - for (int dim = 0; dim < viewFlags.length; dim++) { - if (viewFlags[dim] == 1) { - if (newShape[dim] == 1 && count < 2) { - viewFlags[dim] = 0; - } - - } - } - // Take the original Fixed into account - int[] extendedFlags = new int[underlyingRank()]; - int notFixedDim = 0; - for (int dim = 0; dim < underlyingRank(); dim++) { - int[] temp = flags(); - if (flags()[dim] == 0) { - extendedFlags[dim] = viewFlags[notFixedDim]; - notFixedDim++; - } else { - extendedFlags[dim] = 1; - } - } - return extendedFlags; - } - - /** - * Returns the underlying indices of the element of the given index - * such as there really are in the original ndarray - * - * @param i the index of the element+ - * @return a dataBuffer containing the indices of element - * */ - public DataBuffer getUnderlyingIndicesOf(int i) { - int from = underlyingRank() * i; - //int to = from + underlyingRank(); - int[] res = new int[underlyingRank()]; - for(int j = 0; j< underlyingRank(); j++){ - res[j] = indices.getInt(from + j); - } - - ///int[] arr = Arrays.copyOfRange(indices.asInt(), from, to); - return Nd4j.getDataBufferFactory().createInt(res); - } - - /** - * Returns the indices of the element of the given index in the array context - * - * @param i the index of the element - * @return a dataBuffer containing the indices of element - * */ - public DataBuffer getIndicesOf(int i) { - int from = underlyingRank() * i; - int to = from + underlyingRank(); //not included - - int[] arr = new int[rank]; - int j = 0; // iterator over underlying indices - int k = 0; //iterator over hiddenIdx - for (int dim = 0; dim < rank; dim++) { - if (k < hiddenDimensions().length && hiddenDimensions()[k] == j) { - arr[dim] = 0; - k++; - } else { - arr[dim] = indices.getInt(j); - j++; - } - } - return Nd4j.getDataBufferFactory().createInt(arr); - } - - - public boolean isZero(int... indexes) { - for (int i = 0; i < length(); i++) { - int[] idx = getUnderlyingIndicesOf(i).asInt(); - if (Arrays.equals(idx, translateToPhysical(indexes))) { - return false; - } - } - return true; - } - - @Override - public boolean isView() { - return Shape.offset(shapeInformation) > 0 || data().originalDataBuffer() != null; // TODO or if sparseOffset/flags != [0, ..,0] - } - - @Override - public String getString(long index) { - return null; - } - - - public int getNumHiddenDimension() { - if (hiddenDimensions() == null || hiddenDimensions().length == 0) { - throw new IllegalStateException("HiddenDimension array is malformed"); - } - return hiddenDimensions()[0] == -1 ? 0 : hiddenDimensions().length; - } - - public boolean isSorted() { - return isSorted; - } - - public DataBuffer getValues() { - return values; - } - - public DataBuffer getIndices() { - return indices; - } - - @Override - public INDArray putiColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray putiRowVector(INDArray rowVector) { - return null; - } - - @Override - public INDArray mmul(INDArray other, MMulTranspose mMulTranspose) { - return null; - } - - @Override - public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, MMulTranspose transpose) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, INDArray result, MMulTranspose transpose) { - return null; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public boolean isR() { - return false; - } - - @Override - public boolean isZ() { - return false; - } - - @Override - public boolean isB() { - return false; - } - - @Override - public INDArray castTo(DataType dataType) { - return null; - } - - @Override - public boolean all() { - return false; - } - - @Override - public boolean any() { - return false; - } - - @Override - public boolean none() { - return false; - } - - @Override - public boolean closeable() { - return false; - } - - @Override - public void close() { - - } - - @Override - public boolean wasClosed() { - return false; - } - - @Override - public boolean isS() { - return false; - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCSR.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCSR.java deleted file mode 100644 index cf2f9fe3f..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCSR.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -import org.nd4j.shade.guava.primitives.Ints; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.indexing.*; -import org.nd4j.linalg.util.ArrayUtil; -import org.nd4j.linalg.util.LongUtils; - -import java.util.ArrayList; -import java.util.List; - -import static org.nd4j.base.Preconditions.checkArgument; - - -/** - * @author Audrey Loeffel - */ -public abstract class BaseSparseNDArrayCSR extends BaseSparseNDArray { - protected static final SparseFormat format = SparseFormat.CSR; - protected transient volatile DataBuffer values; - protected transient volatile DataBuffer columnsPointers; - protected transient volatile DataBuffer pointerB; - protected transient volatile DataBuffer pointerE; - - /** - * - * - * The length of the values and columns arrays is equal to the number of non-zero elements in A. - * The length of the pointerB and pointerE arrays is equal to the number of rows in A. - * @param data a double array that contains the non-zero element of the sparse matrix A - * @param columnsPointers Element i of the integer array columns is the number of the column in A that contains the i-th value - * in the values array. - * @param pointerB Element j of this integer array gives the index of the element in the values array that is first - * non-zero element in a row j of A. Note that this index is equal to pointerB(j) - pointerB(1)+1 . - * @param pointerE An integer array that contains row indices, such that pointerE(j)-pointerB(1) is the index of the -* element in the values array that is last non-zero element in a row j of A. - * @param shape Shape of the matrix A - */ - public BaseSparseNDArrayCSR(double[] data, int[] columnsPointers, int[] pointerB, int[] pointerE, long[] shape) { - checkArgument(data.length == columnsPointers.length); - checkArgument(pointerB.length == pointerE.length); - // TODO - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - int valuesSpace = (int) (data.length * THRESHOLD_MEMORY_ALLOCATION); - this.values = Nd4j.getDataBufferFactory().createDouble(valuesSpace); - this.values.setData(data); - this.columnsPointers = Nd4j.getDataBufferFactory().createInt(valuesSpace); - this.columnsPointers.setData(columnsPointers); - this.length = columnsPointers.length; - long pointersSpace = rows; - this.pointerB = Nd4j.getDataBufferFactory().createInt(pointersSpace); - this.pointerB.setData(pointerB); - this.pointerE = Nd4j.getDataBufferFactory().createInt(pointersSpace); - this.pointerE.setData(pointerE); - - - } - - public BaseSparseNDArrayCSR(float[] data, int[] columnsPointers, int[] pointerB, int[] pointerE, long[] shape) { - this(Nd4j.createBuffer(data), columnsPointers, pointerB, pointerE, shape); - } - - public BaseSparseNDArrayCSR(DataBuffer data, int[] columnsPointers, int[] pointerB, int[] pointerE, long[] shape) { - checkArgument(pointerB.length == pointerE.length); - setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, Nd4j.dataType())); - init(shape); - this.values = data; - this.columnsPointers = Nd4j.getDataBufferFactory().createInt(data.length()); - this.columnsPointers.setData(columnsPointers); - this.length = columnsPointers.length; - // The size of these pointers are constant - long pointersSpace = rows; - this.pointerB = Nd4j.getDataBufferFactory().createInt(pointersSpace); - this.pointerB.setData(pointerB); - this.pointerE = Nd4j.getDataBufferFactory().createInt(pointersSpace); - this.pointerE.setData(pointerE); - - } - - public INDArray putScalar(int row, int col, double value) { - - checkArgument(row < rows && 0 <= rows); - checkArgument(col < columns && 0 <= columns); - - int idx = pointerB.getInt(row); - int idxNextRow = pointerE.getInt(row); - - while (columnsPointers.getInt(idx) < col && columnsPointers.getInt(idx) < idxNextRow) { - idx++; - } - if (columnsPointers.getInt(idx) == col) { - values.put(idx, value); - } else { - //Add a new entry in both buffers at a given position - values = addAtPosition(values, length, idx, value); - columnsPointers = addAtPosition(columnsPointers, length, idx, col); - length++; - - // shift the indices of the next rows - pointerE.put(row, pointerE.getInt(row) + 1); - for (int i = row + 1; i < rows; i++) { - pointerB.put(i, pointerB.getInt(i) + 1); - pointerE.put(i, pointerE.getInt(i) + 1); - } - } - return this; - } - - @Override - public INDArray get(INDArrayIndex... indexes) { - //check for row/column vector and point index being 0 - if (indexes.length == 1 && indexes[0] instanceof NDArrayIndexAll || (indexes.length == 2 && (isRowVector() - && indexes[0] instanceof PointIndex && indexes[0].offset() == 0 - && indexes[1] instanceof NDArrayIndexAll - || isColumnVector() && indexes[1] instanceof PointIndex && indexes[0].offset() == 0 - && indexes[0] instanceof NDArrayIndexAll))) - return this; - - indexes = NDArrayIndex.resolve(javaShapeInformation, indexes); - - throw new UnsupportedOperationException("Not implemeted"); - } - - /** - * Return the minor pointers. (columns for CSR, rows for CSC,...) - * */ - public DataBuffer getVectorCoordinates() { - return Nd4j.getDataBufferFactory().create(columnsPointers, 0, length()); - - } - - public double[] getDoubleValues() { - return values.getDoublesAt(0, (int) length); - } - - public double[] getColumns() { - return columnsPointers.getDoublesAt(0, (int) length); - } - - public int[] getPointerBArray() { - return pointerB.asInt(); - } - - public int[] getPointerEArray() { - return pointerE.asInt(); - } - - public SparseFormat getFormat() { - return format; - } - - public DataBuffer getPointerB() { - return Nd4j.getDataBufferFactory().create(pointerB, 0, rows()); - } - - public DataBuffer getPointerE() { - return Nd4j.getDataBufferFactory().create(pointerE, 0, rows()); - } - - private DataBuffer addAtPosition(DataBuffer buf, long dataSize, int pos, double value) { - - DataBuffer buffer = (buf.length() == dataSize) ? reallocate(buf) : buf; - double[] tail = buffer.getDoublesAt(pos, (int) dataSize - pos); - - buffer.put(pos, value); - for (int i = 0; i < tail.length; i++) { - buffer.put(i + pos + 1, tail[i]); - } - return buffer; - } - - @Override - public DataBuffer data() { - return Nd4j.getDataBufferFactory().create(values, 0, length()); - } - - @Override - public INDArray toDense() { - // Dummy way - going to use the conversion routines in level2 (?) - INDArray result = Nd4j.zeros(shape()); - - int[] pointersB = pointerB.asInt(); - int[] pointersE = pointerE.asInt(); - - for (int row = 0; row < rows(); row++) { - for (int idx = pointersB[row]; idx < pointersE[row]; idx++) { - result.put(row, columnsPointers.getInt(idx), values.getNumber(idx)); - } - } - return result; - } - - @Override - public DataBuffer shapeInfoDataBuffer() { - return shapeInformation; - } - - @Override - public boolean equals(Object o) { - //TODO use op - // fixme - if (o == null || !(o instanceof INDArray)) { - return false; - } - INDArray n = (INDArray) o; - if (n.isSparse()) { - BaseSparseNDArray s = (BaseSparseNDArray) n; - switch (s.getFormat()) { - case CSR: - BaseSparseNDArrayCSR csrArray = (BaseSparseNDArrayCSR) s; - if (csrArray.rows() == rows() && csrArray.columns() == columns() - && csrArray.getVectorCoordinates().equals(getVectorCoordinates()) - && csrArray.data().equals(data()) && csrArray.getPointerB().equals(getPointerB()) - && csrArray.getPointerE().equals(getPointerE())) { - return true; - } - break; - default: - INDArray dense = toDense(); - INDArray oDense = s.toDense(); - return dense.equals(oDense); - } - } else { - INDArray dense = toDense(); - return dense.equals(o); - } - return false; - } - - @Override - public boolean isView() { - return false; //todo - } - - @Override - public boolean wasClosed() { - return false; - } - - - @Override - public int underlyingRank() { - return rank; - } - - @Override - public INDArray putiColumnVector(INDArray columnVector) { - return null; - } - - @Override - public INDArray putiRowVector(INDArray rowVector) { - return null; - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java index 23e7f2fcc..a2860b582 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java @@ -48,14 +48,7 @@ public interface INDArray extends Serializable, AutoCloseable { * @return Shape info */ DataBuffer shapeInfoDataBuffer(); - - // TODO: Unused untested method. - /** - * Sparse info - * @return Sparse info. - */ - DataBuffer sparseInfoDataBuffer(); - + /** * Shape info * @return Shape info @@ -2692,47 +2685,6 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray percentile(Number percentile, int... dimension); - /* - * ------------ Sparse methods ------------ - */ - - /** - * Return a array of non-major pointers - * i.e. return the column indexes in case of row-major ndarray - * @return a DataBuffer of indexes - */ - DataBuffer getVectorCoordinates(); - - /** - * Return a dense representation of the sparse ndarray - * */ - INDArray toDense(); - - /** - * Return the number of non-null element - * @return nnz - */ - int nnz(); - - /** - * Return the sparse format (i.e COO, CSR, ...) - * @return format - * @see SparseFormat - * */ - SparseFormat getFormat(); - - //TODO: Undocumented but often used method. - int[] flags(); - - //TODO: Undocumented but often used method. - int[] hiddenDimensions(); - - //TODO: Undocumented but often used method. - int[] sparseOffsets(); - - //TODO: Undocumented but often used method. - int underlyingRank(); - /** * Add an {@link INDArray} * to flatbuffers builder diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/ISparseNDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/ISparseNDArray.java deleted file mode 100644 index 7eac57c8a..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/ISparseNDArray.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -import org.nd4j.linalg.api.buffer.DataBuffer; - -/** - * @author Audrey Loeffel - */ -public interface ISparseNDArray extends INDArray { - /* - * TODO - * Will contain methods such as toDense, toCSRFormat,... - * - * */ - - DataBuffer getVectorCoordinates(); - - INDArray toDense(); - - int nnz(); - - SparseFormat getFormat(); -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/SparseFormat.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/SparseFormat.java deleted file mode 100644 index 28d5ce04d..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/SparseFormat.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -/** - * @author Audrey Loeffel - *
    - *
  • CSR: Compressed Sparse Row
  • - *
  • CSC: Commpressed Sparse Column
  • - *
  • COO: Coordinate Matrix Storage
  • - *
  • None: No sparse format
  • - *
- * @see @see Sparse Matrix Storage Formats - */ -public enum SparseFormat { - CSR, COO, NONE -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/SparseInfoProvider.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/SparseInfoProvider.java deleted file mode 100644 index 76450f6cb..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/SparseInfoProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.ndarray; - -import org.nd4j.linalg.api.buffer.DataBuffer; - -/** - * @author Audrey Loeffel - */ -public interface SparseInfoProvider { - - DataBuffer createSparseInformation(int[] flags, long[] sparseOffsets, int[] hiddenDimensions, int underlyingRank); - - void purgeCache(); -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/shape/SparseDescriptor.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/shape/SparseDescriptor.java deleted file mode 100644 index 5b2fb740f..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/shape/SparseDescriptor.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.shape; - -import java.util.Arrays; - -/** - * @author Audrey Loeffel - */ -public class SparseDescriptor { - - int[] flags; - long[] sparseOffsets; - int[] hiddenDimension; - int underlyingRank; - - public SparseDescriptor(int[] flags, long[] sparseOffsets, int[] hiddenDimension, int underlyingRank) { - this.flags = Arrays.copyOf(flags, flags.length); - this.sparseOffsets = Arrays.copyOf(sparseOffsets, sparseOffsets.length); - this.hiddenDimension = Arrays.copyOf(hiddenDimension, hiddenDimension.length); - this.underlyingRank = underlyingRank; - } - - @Override - public int hashCode() { - int result = underlyingRank; - result = 31 * result + Arrays.hashCode(flags); - result = 31 * result + Arrays.hashCode(sparseOffsets); - result = 31 * result + Arrays.hashCode(hiddenDimension); - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - SparseDescriptor that = (SparseDescriptor) o; - - if (!Arrays.equals(flags, that.flags)) - return false; - if (!Arrays.equals(sparseOffsets, that.sparseOffsets)) - return false; - if (!Arrays.equals(hiddenDimension, that.hiddenDimension)) - return false; - return underlyingRank == that.underlyingRank; - } - - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - - builder.append(flags.length).append(",").append(Arrays.toString(flags)).append(",").append(sparseOffsets.length) - .append(",").append(Arrays.toString(sparseOffsets)).append(",").append(hiddenDimension.length) - .append(",").append(Arrays.toString(hiddenDimension)).append(",").append(underlyingRank); - - String result = builder.toString().replaceAll("\\]", "").replaceAll("\\[", ""); - result = "[" + result + "]"; - - return result; - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseBlasWrapper.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseBlasWrapper.java index fa6963891..e683a8f57 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseBlasWrapper.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseBlasWrapper.java @@ -217,34 +217,6 @@ public abstract class BaseBlasWrapper implements BlasWrapper { return a; } - @Override - public INDArray gemm(double alpha, INDArray a, INDArray b, double beta, INDArray c) { - LinAlgExceptions.assertMatrix(a, b, c); - - if (a.data().dataType() == DataType.FLOAT) { - return gemm((float) alpha, a, b, (float) beta, c); - } - - - level3().gemm(BlasBufferUtil.getCharForTranspose(a), BlasBufferUtil.getCharForTranspose(b), - BlasBufferUtil.getCharForTranspose(c), alpha, a, b, beta, c); - return c; - } - - @Override - public INDArray gemm(float alpha, INDArray a, INDArray b, float beta, INDArray c) { - LinAlgExceptions.assertMatrix(a, b, c); - - - if (a.data().dataType() == DataType.DOUBLE) { - return gemm((double) alpha, a, b, (double) beta, c); - } - - level3().gemm(BlasBufferUtil.getCharForTranspose(a), BlasBufferUtil.getCharForTranspose(b), - BlasBufferUtil.getCharForTranspose(c), alpha, a, b, beta, c); - return c; - } - @Override public INDArray gesv(INDArray a, int[] ipiv, INDArray b) { throw new UnsupportedOperationException(); diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseSparseBlasWrapper.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseSparseBlasWrapper.java deleted file mode 100644 index 13b14ffe7..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseSparseBlasWrapper.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.factory; - -import org.nd4j.linalg.api.blas.Lapack; -import org.nd4j.linalg.api.blas.Level1; -import org.nd4j.linalg.api.blas.Level2; -import org.nd4j.linalg.api.blas.Level3; -import org.nd4j.linalg.api.ndarray.INDArray; - -/** - * @author Audrey Loeffel - */ -public abstract class BaseSparseBlasWrapper implements BlasWrapper { - - - @Override - public Lapack lapack() { - return Nd4j.sparseFactory().lapack(); - } - - @Override - public Level1 level1() { - return Nd4j.sparseFactory().level1(); - } - - @Override - public Level2 level2() { - return Nd4j.sparseFactory().level2(); - - } - - @Override - public Level3 level3() { - return Nd4j.sparseFactory().level3(); - - } - - // ================== TODO ==================== - @Override - public INDArray swap(INDArray x, INDArray y) { - return null; - } - - @Override - public INDArray scal(double alpha, INDArray x) { - return null; - } - - @Override - public INDArray scal(float alpha, INDArray x) { - return null; - } - - @Override - public INDArray copy(INDArray x, INDArray y) { - return null; - } - - @Override - public INDArray axpy(double da, INDArray dx, INDArray dy) { - return null; - } - - @Override - public INDArray axpy(float da, INDArray dx, INDArray dy) { - return null; - } - - @Override - public INDArray axpy(Number da, INDArray dx, INDArray dy) { - return null; - } - - @Override - public double dot(INDArray x, INDArray y) { - return 0; - } - - @Override - public double nrm2(INDArray x) { - return 0; - } - - @Override - public double asum(INDArray x) { - return 0; - } - - @Override - public int iamax(INDArray x) { - return 0; - } - - @Override - public INDArray gemv(Number alpha, INDArray a, INDArray x, double beta, INDArray y) { - return null; - } - - @Override - public INDArray gemv(double alpha, INDArray a, INDArray x, double beta, INDArray y) { - return null; - } - - @Override - public INDArray gemv(float alpha, INDArray a, INDArray x, float beta, INDArray y) { - return null; - } - - @Override - public INDArray ger(Number alpha, INDArray x, INDArray y, INDArray a) { - return null; - } - - @Override - public INDArray ger(double alpha, INDArray x, INDArray y, INDArray a) { - return null; - } - - @Override - public INDArray ger(float alpha, INDArray x, INDArray y, INDArray a) { - return null; - } - - @Override - public INDArray gemm(double alpha, INDArray a, INDArray b, double beta, INDArray c) { - return null; - } - - @Override - public INDArray gemm(float alpha, INDArray a, INDArray b, float beta, INDArray c) { - return null; - } - - @Override - public INDArray gesv(INDArray a, int[] ipiv, INDArray b) { - return null; - } - - @Override - public void checkInfo(String name, int info) { - - } - - @Override - public INDArray sysv(char uplo, INDArray a, int[] ipiv, INDArray b) { - return null; - } - - @Override - public int syev(char jobz, char uplo, INDArray a, INDArray w) { - return 0; - } - - @Override - public int syevx(char jobz, char range, char uplo, INDArray a, double vl, double vu, int il, int iu, double abstol, - INDArray w, INDArray z) { - return 0; - } - - @Override - public int syevx(char jobz, char range, char uplo, INDArray a, float vl, float vu, int il, int iu, float abstol, - INDArray w, INDArray z) { - return 0; - } - - @Override - public int syevd(char jobz, char uplo, INDArray A, INDArray w) { - return 0; - } - - @Override - public int syevr(char jobz, char range, char uplo, INDArray a, double vl, double vu, int il, int iu, double abstol, - INDArray w, INDArray z, int[] isuppz) { - return 0; - } - - @Override - public int syevr(char jobz, char range, char uplo, INDArray a, float vl, float vu, int il, int iu, float abstol, - INDArray w, INDArray z, int[] isuppz) { - return 0; - } - - @Override - public int syevr(char jobz, char range, char uplo, INDArray a, float vl, float vu, int il, int iu, Number abstol, - INDArray w, INDArray z, int[] isuppz) { - return 0; - } - - @Override - public void posv(char uplo, INDArray A, INDArray B) { - - } - - @Override - public int geev(char jobvl, char jobvr, INDArray A, INDArray WR, INDArray WI, INDArray VL, INDArray VR) { - return 0; - } - - @Override - public int sygvd(int itype, char jobz, char uplo, INDArray A, INDArray B, INDArray W) { - return 0; - } - - @Override - public void gelsd(INDArray A, INDArray B) { - - } - - @Override - public void geqrf(INDArray A, INDArray tau) { - - } - - @Override - public void ormqr(char side, char trans, INDArray A, INDArray tau, INDArray C) { - - } - - @Override - public void saxpy(double alpha, INDArray x, INDArray y) { - - } - - @Override - public void saxpy(float alpha, INDArray x, INDArray y) { - - } -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseSparseNDArrayFactory.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseSparseNDArrayFactory.java deleted file mode 100644 index 714c4cfe2..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BaseSparseNDArrayFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.factory; - - -/** - * @author Audrey Loeffel - */ -public abstract class BaseSparseNDArrayFactory extends BaseNDArrayFactory { - // TODO override needed methods -} diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BlasWrapper.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BlasWrapper.java index b0f7dffbf..23fecb85c 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BlasWrapper.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/BlasWrapper.java @@ -153,22 +153,7 @@ public interface BlasWrapper { * Compute A <- alpha * x * y^T + A (general rank-1 update) */ INDArray ger(float alpha, INDArray x, INDArray y, INDArray a); - - /** - * ************************************************************************ - * BLAS Level 3 - */ - @Deprecated - INDArray gemm(double alpha, INDArray a, INDArray b, double beta, INDArray c); - - /** - * Compute c <- a*b + beta * c (general matrix matrix - * multiplication) - */ - @Deprecated - INDArray gemm(float alpha, INDArray a, INDArray b, float beta, INDArray c); - - + /** * ************************************************************************ * LAPACK diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/NDArrayFactory.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/NDArrayFactory.java index 3e981118b..4072f5c1e 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/NDArrayFactory.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/NDArrayFactory.java @@ -1413,28 +1413,4 @@ public interface NDArrayFactory { // =========== String methods ============ INDArray create(Collection strings, long[] shape, char order); - - // =========== Sparse methods =========== - - INDArray createSparseCSR(double[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape); - - INDArray createSparseCSR(float[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape); - - INDArray createSparseCSR(DataBuffer data, int[] columns, int[] pointerB, int[] pointerE, long[] shape); - - INDArray createSparseCOO(double[] values, long[][] indices, long[] shape); - - INDArray createSparseCOO(float[] values, long[][] indices, long[] shape); - - INDArray createSparseCOO(double[] values, int[][] indices, long[] shape); - - INDArray createSparseCOO(float[] values, int[][] indices, long[] shape); - - INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] shape); - - INDArray createSparseCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape); - - INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, - int[] hiddenDimensions, int underlyingRank, long[] shape); - } diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java index 2d9b8774c..98f92aaaa 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/factory/Nd4j.java @@ -119,16 +119,13 @@ public class Nd4j { @Deprecated public final static String DTYPE = ND4JSystemProperties.DTYPE; private final static String BLAS_OPS = "blas.ops"; - private final static String SPARSE_BLAS_OPS = "sparseblas.ops"; public final static String NATIVE_OPS = "native.ops"; private final static String ORDER_KEY = "ndarray.order"; private final static String NDARRAY_FACTORY_CLASS = "ndarrayfactory.class"; - private final static String SPARSE_NDARRAY_FACTORY_CLASS = "sparsendarrayfactory.class"; private final static String OP_EXECUTIONER = "opexec"; public final static String DISTRIBUTION = "dist"; private final static String SHAPEINFO_PROVIDER = "shapeinfoprovider"; - private final static String SPARSEINFO_PROVIDER = "sparseinfoprovider"; private final static String CONSTANT_PROVIDER = "constantsprovider"; private final static String AFFINITY_MANAGER = "affinitymanager"; //disable toString() on compressed arrays for debugging. Should be off by default. @@ -156,14 +153,11 @@ public class Nd4j { private static DataBufferFactory DATA_BUFFER_FACTORY_INSTANCE; private static BlasWrapper BLAS_WRAPPER_INSTANCE; - private static BlasWrapper SPARSE_BLAS_WRAPPER_INSTANCE; protected static NDArrayFactory INSTANCE; - private static NDArrayFactory SPARSE_INSTANCE; private static ConvolutionInstance CONVOLUTION_INSTANCE; private static OpExecutioner OP_EXECUTIONER_INSTANCE; private static DistributionFactory DISTRIBUTION_FACTORY; private static ShapeInfoProvider shapeInfoProvider; - private static SparseInfoProvider sparseInfoProvider; private static ConstantHandler constantHandler; private static AffinityManager affinityManager; private static MemoryManager memoryManager; @@ -800,14 +794,6 @@ public class Nd4j { return INSTANCE; } - /** - * The factory used for creating sparse arrays. - * @return the factory used for creating sparse arrays. - */ - public static NDArrayFactory sparseFactory() { - return SPARSE_INSTANCE; - } - /** * See {@link org.nd4j.linalg.api.ndarray.INDArray#cumsum(int)} with Integer.MAX_VALUE for full array reduction. * @@ -1700,14 +1686,6 @@ public class Nd4j { return BLAS_WRAPPER_INSTANCE; } - /** - * Retreive the sparse BLAS wrapper. - * @return the sparse BLAS wrapper. - */ - public static BlasWrapper getSparseBlasWrapper() { - return SPARSE_BLAS_WRAPPER_INSTANCE; - } - /** * Sort an ndarray along a particular dimension.
* Note that the input array is modified in-place. @@ -5159,8 +5137,6 @@ public class Nd4j { affinityManager = affinityManagerClazz.newInstance(); Class ndArrayFactoryClazz = (Class) Class.forName( pp.toString(NDARRAY_FACTORY_CLASS)); - Class sparseNDArrayClazz = (Class) Class.forName( - pp.toString(SPARSE_NDARRAY_FACTORY_CLASS)); Class convolutionInstanceClazz = (Class) Class .forName(pp.toString(CONVOLUTION_OPS, DefaultConvolutionInstance.class.getName())); String defaultName = pp.toString(DATA_BUFFER_OPS, DefaultDataBufferFactory.class.getName()); @@ -5168,8 +5144,6 @@ public class Nd4j { .forName(pp.toString(DATA_BUFFER_OPS, defaultName)); Class shapeInfoProviderClazz = (Class) Class .forName(pp.toString(SHAPEINFO_PROVIDER)); - Class sparseInfoProviderClazz = (Class) Class.forName( - pp.toString(SPARSEINFO_PROVIDER)); Class constantProviderClazz = (Class) Class .forName(pp.toString(CONSTANT_PROVIDER)); @@ -5187,8 +5161,6 @@ public class Nd4j { Class blasWrapperClazz = (Class) Class .forName(pp.toString(BLAS_OPS)); - Class sparseBlasWrapperClazz = (Class) Class - .forName(pp.toString(SPARSE_BLAS_OPS)); String clazzName = pp.toString(DISTRIBUTION, DefaultDistributionFactory.class.getName()); Class distributionFactoryClazz = (Class) Class.forName(clazzName); @@ -5196,7 +5168,6 @@ public class Nd4j { memoryManager = memoryManagerClazz.newInstance(); constantHandler = constantProviderClazz.newInstance(); shapeInfoProvider = shapeInfoProviderClazz.newInstance(); - sparseInfoProvider = sparseInfoProviderClazz.newInstance(); workspaceManager = workspaceManagerClazz.newInstance(); Class opExecutionerClazz = (Class) Class @@ -5205,10 +5176,8 @@ public class Nd4j { OP_EXECUTIONER_INSTANCE = opExecutionerClazz.newInstance(); Constructor c2 = ndArrayFactoryClazz.getConstructor(DataType.class, char.class); INSTANCE = (NDArrayFactory) c2.newInstance(dtype, ORDER); - SPARSE_INSTANCE = sparseNDArrayClazz.newInstance(); CONVOLUTION_INSTANCE = convolutionInstanceClazz.newInstance(); BLAS_WRAPPER_INSTANCE = blasWrapperClazz.newInstance(); - SPARSE_BLAS_WRAPPER_INSTANCE = sparseBlasWrapperClazz.newInstance(); DATA_BUFFER_FACTORY_INSTANCE = dataBufferFactoryClazz.newInstance(); DISTRIBUTION_FACTORY = distributionFactoryClazz.newInstance(); @@ -5306,14 +5275,6 @@ public class Nd4j { return shapeInfoProvider; } - /** - * - * @return Sparse shape info provider - */ - public static SparseInfoProvider getSparseInfoProvider() { - return sparseInfoProvider; - } - /** * * @return constant handler diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/SparseNd4jBlas.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/SparseNd4jBlas.java deleted file mode 100644 index 76d65fa01..000000000 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-native-api/src/main/java/org/nd4j/nativeblas/SparseNd4jBlas.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.nativeblas; - -import org.nd4j.linalg.api.blas.Blas; - -public abstract class SparseNd4jBlas implements Blas { - - public SparseNd4jBlas() { - - } - - /** - * Returns the BLAS library vendor - * - * @return the BLAS library vendor - */ - @Override - public Vendor getBlasVendor() { - int vendor = getBlasVendorId(); - boolean isUnknowVendor = ((vendor > Vendor.values().length - 1) || (vendor <= 0)); - if (isUnknowVendor) { - return Vendor.UNKNOWN; - } - return Vendor.values()[vendor]; - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/DirectSparseInfoProvider.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/DirectSparseInfoProvider.java deleted file mode 100644 index 20a5b7b87..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/DirectSparseInfoProvider.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas; - -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.BaseSparseInfoProvider; -import org.nd4j.linalg.api.shape.Shape; -import org.nd4j.linalg.api.shape.SparseDescriptor; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author Audrey Loeffel - */ -public class DirectSparseInfoProvider extends BaseSparseInfoProvider { - - private Map sparseCache = new ConcurrentHashMap<>(); - private AtomicInteger counter = new AtomicInteger(0); - private static final int MAX_ENTRIES = 100; - - @Override - public DataBuffer createSparseInformation(int[] flags, long[] sparseOffsets, int[] hiddenDimensions, int underlyingRank) { - - SparseDescriptor descriptor = new SparseDescriptor(flags, sparseOffsets, hiddenDimensions, underlyingRank); - - if(!sparseCache.containsKey(descriptor)){ - if(counter.get() < MAX_ENTRIES){ - if(!sparseCache.containsKey(descriptor)){ - counter.incrementAndGet(); - DataBuffer buffer = Shape.createSparseInformation(flags, sparseOffsets, hiddenDimensions, underlyingRank); - sparseCache.put(descriptor, buffer); - return buffer; - } - } else { - return Shape.createSparseInformation(flags, sparseOffsets, hiddenDimensions, underlyingRank); - } - } - return sparseCache.get(descriptor); - } - - @Override - public void purgeCache() { - sparseCache = new ConcurrentHashMap<>(); - } - -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java index daebc041e..9931fcaa9 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java @@ -1612,55 +1612,6 @@ public class JCublasNDArrayFactory extends BaseNativeNDArrayFactory { } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - @Override - public INDArray createSparseCSR(double[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCSR(float[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCSR(DataBuffer data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(double[] values, long[][] indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(float[] values, long[][] indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(double[] values, int[][] indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(float[] values, int[][] indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, int[] hiddenDimensions, int underlyingRank, long[] shape) { - throw new UnsupportedOperationException(); - } @Override public INDArray sortCooIndices(INDArray x) { diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCusparseNDArrayCOO.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCusparseNDArrayCOO.java deleted file mode 100644 index 1fbea9e05..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCusparseNDArrayCOO.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas; - -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCOO; - -/** - * @author Audrey Loeffel - */ -public class JCusparseNDArrayCOO extends BaseSparseNDArrayCOO { - public JCusparseNDArrayCOO(DataBuffer values, DataBuffer indices, long[] shape) { - super(values, indices, shape); - } - - public JCusparseNDArrayCOO(double[] values, long[][] indices, long[] shape) { - super(values, indices, shape); - } - - public JCusparseNDArrayCOO(float[] values, long[][] indices, long[] shape) { - super(values, indices, shape); - } - - public JCusparseNDArrayCOO(double[] values, int[][] indices, long[] shape) { - super(values, indices, shape); - } - - public JCusparseNDArrayCOO(float[] values, int[][] indices, long[] shape) { - super(values, indices, shape); - } - - public JCusparseNDArrayCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - super(values, indices, sparseInformation, shape); - } - - public JCusparseNDArrayCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, int[] hiddenDimensions, int underlyingRank, long[] shape) { - super(values, indices, sparseOffsets, flags, hiddenDimensions, underlyingRank, shape); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCusparseNDArrayFactory.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCusparseNDArrayFactory.java deleted file mode 100644 index e4e85d531..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCusparseNDArrayFactory.java +++ /dev/null @@ -1,570 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas; - -import lombok.extern.slf4j.Slf4j; -import org.bytedeco.javacpp.Pointer; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.buffer.DataTypeEx; -import org.nd4j.linalg.api.memory.MemoryWorkspace; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.api.ndarray.ISparseNDArray; -import org.nd4j.linalg.factory.BaseSparseNDArrayFactory; -import org.nd4j.linalg.jcublas.blas.*; -import org.nd4j.nativeblas.NativeOps; -import org.nd4j.nativeblas.NativeOpsHolder; - -import java.io.File; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Random; - -/** - * @author Audrey Loeffel - */ -@Slf4j -public class JCusparseNDArrayFactory extends BaseSparseNDArrayFactory{ - - private NativeOps nativeOps = NativeOpsHolder.getInstance().getDeviceNativeOps(); - - public JCusparseNDArrayFactory(){} - - @Override - public INDArray create(float[] data, int[] shape, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, char order, DataType dataType) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(long[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(int[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(short[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(byte[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(boolean[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(List list, int[] shape) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(long[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(int[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(short[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(byte[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(boolean[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(List list, long[] shape) { - return null; - } - - @Override - public INDArray create(long rows, long columns, long[] stride, long offset) { - return null; - } - - @Override - public INDArray empty(DataType type) { - throw new IllegalStateException(); - } - - @Override - public void createBlas() { - blas = new SparseCudaBlas(); - } - - @Override - public void createLevel1() { - level1 = new JcusparseLevel1(); - } - - @Override - public void createLevel2() { - level2 = new JcusparseLevel2(); - } - - @Override - public void createLevel3() { - level3 = new JcusparseLevel3(); - } - - @Override - public void createLapack() { - lapack = new JcusparseLapack(); - } - - @Override - public INDArray create(int[] shape, DataBuffer buffer) { - return null; - } - - @Override - public INDArray toFlattened(char order, Collection matrices) { - return null; - } - - @Override - public INDArray create(double[][] data) { - return null; - } - - @Override - public INDArray create(double[][] data, char ordering) { - return null; - } - - @Override - public INDArray specialConcat(int dimension, INDArray... toConcat) { - return null; - } - - @Override - public INDArray pullRows(INDArray source, int sourceDimension, long[] indexes) { - return null; - } - - @Override - public INDArray pullRows(INDArray source, INDArray destination, int sourceDimension, int[] indexes) { - return null; - } - - @Override - public void shuffle(INDArray array, Random rnd, int... dimension) { - - } - - @Override - public void shuffle(Collection array, Random rnd, int... dimension) { - - } - - @Override - public void shuffle(List array, Random rnd, List dimensions) { - - } - - @Override - public INDArray average(INDArray target, INDArray[] arrays) { - return null; - } - - @Override - public INDArray average(INDArray[] arrays) { - return null; - } - - @Override - public INDArray average(Collection arrays) { - return null; - } - - @Override - public INDArray accumulate(INDArray target, INDArray... arrays) { - return null; - } - - @Override - public INDArray average(INDArray target, Collection arrays) { - return null; - } - - @Override - public INDArray create(DataBuffer data) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long rows, long columns, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(DataBuffer data, int[] shape) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] shape) { - return null; - } - - @Override - public INDArray create(DataBuffer data, int[] shape, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] shape, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(float[][] floats) { - return null; - } - - @Override - public INDArray create(float[][] data, char ordering) { - return null; - } - - @Override - public INDArray create(float[] data, int[] shape, int[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer buffer, int[] shape, long offset) { - return null; - } - - @Override - public INDArray create(int[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(long[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(DataType dataType, long[] shape, char ordering, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(DataType dataType, long[] shape, long[] strides, char ordering, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray createUninitialized(int[] shape, char ordering) { - return null; - } - - @Override - public INDArray createUninitialized(long[] shape, char ordering) { - return null; - } - - @Override - public INDArray createUninitialized(DataType dataType, long[] shape, char ordering, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray createUninitializedDetached(DataType dataType, char ordering, long... shape) { - return null; - } - - @Override - public INDArray create(DataBuffer data, int[] newShape, int[] newStride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, long ews, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering, DataType dataType) { - return null; - } - - @Override - public INDArray create(float[] data, int[] shape, long offset, Character order) { - return null; - } - - @Override - public INDArray create(float[] data, long rows, long columns, int[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(List list, int[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(List list, long[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, int[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, char order, long offset) { - return null; - } - - @Override - public INDArray convertDataEx(DataTypeEx typeSrc, INDArray source, DataTypeEx typeDst) { - return null; - } - - @Override - public DataBuffer convertDataEx(DataTypeEx typeSrc, DataBuffer source, DataTypeEx typeDst) { - return null; - } - - @Override - public void convertDataEx(DataTypeEx typeSrc, DataBuffer source, DataTypeEx typeDst, DataBuffer target) { - - } - - @Override - public void convertDataEx(DataTypeEx typeSrc, Pointer source, DataTypeEx typeDst, Pointer target, long length) { - - } - - @Override - public void convertDataEx(DataTypeEx typeSrc, Pointer source, DataTypeEx typeDst, DataBuffer buffer) { - - } - - @Override - public INDArray createFromNpyPointer(Pointer pointer) { - return null; - } - - @Override - public INDArray createFromNpyHeaderPointer(Pointer pointer) { - return null; - } - - @Override - public INDArray createFromNpyFile(File file) { - return null; - } - - @Override - public Map createFromNpzFile(File file) throws Exception { - return null; - } - - @Override - public Pointer convertToNumpy(INDArray array) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray[] tear(INDArray tensor, int... dimensions) { - return new INDArray[0]; - } - - @Override - public INDArray sort(INDArray x, boolean descending) { - return null; - } - - @Override - public INDArray sort(INDArray x, boolean descending, int... dimensions) { - return null; - } - - @Override - public INDArray sortCooIndices(INDArray x) { - //TODO - throw new UnsupportedOperationException(); - } - - @Override - public INDArray create(float[] data, long[] shape, long offset, Character order) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long offset, Character order) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(Collection strings, long[] shape, char order) { - return null; - } - - @Override - public ISparseNDArray createSparseCSR(double[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - return new JcusparseNDArrayCSR(data, columns, pointerB, pointerE, shape); - } - - @Override - public INDArray createSparseCSR(float[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCSR(DataBuffer data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(double[] values, long[][] indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(float[] values, long[][] indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(double[] values, int[][] indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(float[] values, int[][] indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, sparseInformation, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, int[] hiddenDimensions, int underlyingRank, long[] shape) { - return new JCusparseNDArrayCOO(values, indices, sparseOffsets, flags, hiddenDimensions, underlyingRank, shape); - } - - -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java deleted file mode 100644 index ae738f5c3..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas; - -import com.google.flatbuffers.FlatBufferBuilder; -import org.nd4j.linalg.api.blas.params.MMulTranspose; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCSR; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.api.shape.LongShapeDescriptor; - -/** - * @author Audrey Loeffel - */ -public class JcusparseNDArrayCSR extends BaseSparseNDArrayCSR { - /** - * The length of the values and columns arrays is equal to the number of non-zero elements in A. - * The length of the pointerB and pointerE arrays is equal to the number of rows in A. - * - * @param data a double array that contains the non-zero element of the sparse matrix A - * @param columnsPointers Element i of the integer array columns is the number of the column in A that contains the i-th value - * in the values array. - * @param pointerB Element j of this integer array gives the index of the element in the values array that is first - * non-zero element in a row j of A. Note that this index is equal to pointerB(j) - pointerB(1)+1 . - * @param pointerE An integer array that contains row indices, such that pointerE(j)-pointerB(1) is the index of the - * element in the values array that is last non-zero element in a row j of A. - * @param shape Shape of the matrix A - */ - public JcusparseNDArrayCSR(double[] data, int[] columnsPointers, int[] pointerB, int[] pointerE, long[] shape) { - super(data, columnsPointers, pointerB, pointerE, shape); - } - - public JcusparseNDArrayCSR(float[] data, int[] columnsPointers, int[] pointerB, int[] pointerE, long[] shape) { - super(data, columnsPointers, pointerB, pointerE, shape); - } - - public JcusparseNDArrayCSR(DataBuffer data, int[] columnsPointers, int[] pointerB, int[] pointerE, long[] shape) { - super(data, columnsPointers, pointerB, pointerE, shape); - } - - @Override - public String getString(long index) { - return null; - } - - @Override - public INDArray repeat(int dimension, long... repeats) { - return null; - } - - @Override - public INDArray mmul(INDArray other, MMulTranspose mMulTranspose) { - return null; - } - - @Override - public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, MMulTranspose transpose) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, INDArray result, MMulTranspose transpose) { - return null; - } - - @Override - public long getLong(long index) { - return 0; - } - - @Override - public INDArray reshape(char order, int... newShape) { - return null; - } - - @Override - public INDArray reshape(char order, boolean enforceView, long... newShape) { - return null; - } - - @Override - public INDArray reshape(int[] shape) { - return null; - } - - @Override - public LongShapeDescriptor shapeDescriptor() { - return null; - } - - - @Override - public int toFlatArray(FlatBufferBuilder builder) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isEmpty() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isR() { - return false; - } - - @Override - public boolean isZ() { - return false; - } - - @Override - public boolean isB() { - return false; - } - - @Override - public boolean isS() { - return false; - } - - @Override - public INDArray castTo(DataType dataType) { - return null; - } - - @Override - public boolean all() { - return false; - } - - @Override - public boolean any() { - return false; - } - - @Override - public boolean none() { - return false; - } - - @Override - public boolean closeable() { - return false; - } - - @Override - public void close() { - - } - - @Override - public INDArray assign(boolean value) { - return assign(value ? 1 : 0); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/SparseBlasWrapper.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/SparseBlasWrapper.java deleted file mode 100644 index 274505b17..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/SparseBlasWrapper.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas; - -import org.nd4j.linalg.factory.BaseSparseBlasWrapper; - -/** - * @author Audrey Loeffel - */ -public class SparseBlasWrapper extends BaseSparseBlasWrapper { -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLapack.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLapack.java deleted file mode 100644 index d0d4c6eb0..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLapack.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLapack; - -/** - * @author Audrey Loeffel - */ -public class JcusparseLapack extends SparseBaseLapack { -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel1.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel1.java deleted file mode 100644 index b3c35fdbb..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel1.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLevel1; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.INDArray; - -/** - * @author Audrey Loeffel - */ -public class JcusparseLevel1 extends SparseBaseLevel1 { - - @Override - protected double ddoti(long N, INDArray X, DataBuffer indx, INDArray Y) { - return 0; - } - - @Override - protected double sdoti(long N, INDArray X, DataBuffer indx, INDArray Y) { - return 0; - } - - @Override - protected double hdoti(long N, INDArray X, DataBuffer indx, INDArray Y) { - return 0; - } - - @Override - protected double snrm2(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected double dnrm2(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected double hnrm2(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected double dasum(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected double sasum(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected double hasum(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected int isamax(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected int idamax(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected int ihamax(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected int isamin(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected int idamin(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected int ihamin(long N, INDArray X, int incx) { - return 0; - } - - @Override - protected void daxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y) { - - } - - @Override - protected void saxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y) { - - } - - @Override - protected void haxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y) { - - } - - @Override - protected void droti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s) { - - } - - @Override - protected void sroti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s) { - - } - - @Override - protected void hroti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s) { - - } - - @Override - protected void dscal(long N, double a, INDArray X, int incx) { - - } - - @Override - protected void sscal(long N, double a, INDArray X, int incx) { - - } - - @Override - protected void hscal(long N, double a, INDArray X, int incx) { - - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel2.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel2.java deleted file mode 100644 index f7c5f4bf4..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel2.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLevel2; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.INDArray; - -/** - * @author Audrey Loeffel - */ -public class JcusparseLevel2 extends SparseBaseLevel2 { - - - @Override - protected void scoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, INDArray x, INDArray y) { - - } - - @Override - protected void dcoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, INDArray x, INDArray y) { - - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel3.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel3.java deleted file mode 100644 index 3573eee58..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcusparseLevel3.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLevel3; - -/** - * @author Audrey Loeffel - */ -public class JcusparseLevel3 extends SparseBaseLevel3 { -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/SparseCudaBlas.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/SparseCudaBlas.java deleted file mode 100644 index 702c818e6..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/SparseCudaBlas.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.jcublas.blas; - - -import org.nd4j.linalg.api.blas.Blas; -import org.nd4j.nativeblas.SparseNd4jBlas; - -/** - * @author Audrey Loeffel - */ -public class SparseCudaBlas extends SparseNd4jBlas { - @Override - public void setMaxThreads(int num){ - - } - - @Override - public int getMaxThreads() { - return 0; - } - - @Override - public int getBlasVendorId() { - return 0; - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/resources/nd4j-jcublas.properties b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/resources/nd4j-jcublas.properties index 3ed95d140..09a82d86d 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/resources/nd4j-jcublas.properties +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/resources/nd4j-jcublas.properties @@ -37,6 +37,3 @@ fft = org.nd4j.linalg.jcublas.fft.JcudaFft opexec.mode= native random=org.nd4j.linalg.jcublas.rng.CudaNativeRandom -sparseinfoprovider = org.nd4j.linalg.jcublas.DirectSparseInfoProvider -sparseblas.ops = org.nd4j.linalg.jcublas.SparseBlasWrapper -sparsendarrayfactory.class = org.nd4j.linalg.jcublas.JCusparseNDArrayFactory diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuNDArrayFactory.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuNDArrayFactory.java index ff4ac6bcc..a328d788e 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuNDArrayFactory.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuNDArrayFactory.java @@ -1054,59 +1054,6 @@ public class CpuNDArrayFactory extends BaseNativeNDArrayFactory { convertDataEx(typeSrc, source.addressPointer(), typeDst, target.addressPointer(), target.length()); } - - - @Override - public INDArray createSparseCSR(double[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCSR(float[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCSR(DataBuffer data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(double[] values, int[][] indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(float[] values, int[][] indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(double[] values, long[][] indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(float[] values, long[][] indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] shape) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - throw new UnsupportedOperationException(); - } - - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, int[] hiddenDimensions, int underlyingRank, long[] shape) { - throw new UnsupportedOperationException(); - } - @Override public INDArray sort(INDArray x, boolean descending) { if (x.isScalar()) diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuSparseNDArrayFactory.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuSparseNDArrayFactory.java deleted file mode 100644 index e83f7a646..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuSparseNDArrayFactory.java +++ /dev/null @@ -1,606 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu; - -import lombok.extern.slf4j.Slf4j; -import org.bytedeco.javacpp.*; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.buffer.DataTypeEx; -import org.nd4j.linalg.api.memory.MemoryWorkspace; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCOO; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.api.ndarray.SparseFormat; -import org.nd4j.linalg.cpu.nativecpu.blas.*; -import org.nd4j.linalg.factory.BaseSparseNDArrayFactory; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.primitives.Pair; -import org.nd4j.nativeblas.LongPointerWrapper; -import org.nd4j.nativeblas.NativeOpsHolder; - -import java.io.File; -import java.util.*; - -/** - * @author Audrey Loeffel - */ - -// TODO : Implement the methods - -@Slf4j -public class CpuSparseNDArrayFactory extends BaseSparseNDArrayFactory { - - public CpuSparseNDArrayFactory(){} - - @Override - public INDArray createSparseCSR(double[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape){ - return new SparseNDArrayCSR(data, columns, pointerB, pointerE, shape); - } - @Override - public INDArray createSparseCSR(float[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape){ - return new SparseNDArrayCSR(data, columns, pointerB, pointerE, shape); - } - @Override - public INDArray createSparseCSR(DataBuffer data, int[] columns, int[] pointerB, int[] pointerE, long[] shape){ - return new SparseNDArrayCSR(data, columns, pointerB, pointerE, shape); - } - - @Override - public INDArray createSparseCOO(double[] values, int[][] indices, long[] shape){ - return new SparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(float[] values, int[][] indices, long[] shape){ - return new SparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray create(DataType dataType, long[] shape, char ordering, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(DataType dataType, long[] shape, long[] strides, char ordering, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray createUninitialized(DataType dataType, long[] shape, char ordering, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray createSparseCOO(double[] values, long[][] indices, long[] shape) { - return new SparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(float[] values, long[][] indices, long[] shape) { - return new SparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] shape){ - return new SparseNDArrayCOO(values, indices, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, int[] hiddenDimensions, int underlyingRank, long[] shape) { - return new SparseNDArrayCOO(values, indices, sparseOffsets, flags, hiddenDimensions, underlyingRank, shape); - } - - @Override - public INDArray createSparseCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - return new SparseNDArrayCOO(values, indices, sparseInformation, shape); - } - // TODO -> - - - @Override - public INDArray pullRows(INDArray source, int sourceDimension, long[] indexes) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(long[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(int[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(short[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(byte[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(boolean[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(long[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(int[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(short[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(byte[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(boolean[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] shape) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] shape, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(List list, long[] shape) { - return null; - } - - @Override - public INDArray create(long rows, long columns, long[] stride, long offset) { - return null; - } - - @Override - public INDArray create(long[] shape, char ordering) { - return null; - } - - @Override - public INDArray createUninitialized(long[] shape, char ordering) { - return null; - } - - @Override - public INDArray createUninitializedDetached(DataType dataType, char ordering, long... shape){ - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, long ews, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering, DataType dataType) { - return null; - } - - @Override - public INDArray create(List list, long[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, char order, long offset) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, char order, DataType dataType) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray specialConcat(int dimension, INDArray... toConcat) { - return null; - } - - @Override - public INDArray pullRows(INDArray source, INDArray destination, int sourceDimension, int[] indexes) { - return null; - } - - @Override - public INDArray create(float[] data, int[] shape, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(List list, int[] shape) { - return null; - } - - static{ - Nd4j.getBlasWrapper(); - } - // contructors ? - - @Override - public void createBlas(){ blas = new SparseCpuBlas();} - - @Override - public void createLevel1() { - level1 = new SparseCpuLevel1(); - } - - @Override - public void createLevel2() { - level2 = new SparseCpuLevel2(); - } - - @Override - public void createLevel3() { level3 = new SparseCpuLevel3(); } - - @Override - public void createLapack() { - lapack = new SparseCpuLapack(); - } - - @Override - public INDArray create(int[] shape, DataBuffer buffer) { - return null; - } - - @Override - public INDArray toFlattened(char order, Collection matrices) { - return null; - } - - @Override - public INDArray create(double[][] data) { - return null; - } - - @Override - public INDArray create(double[][] data, char ordering) { - return null; - } - - @Override - public void shuffle(INDArray array, Random rnd, int... dimension) { - - } - - @Override - public void shuffle(Collection array, Random rnd, int... dimension) { - - } - - @Override - public void shuffle(List array, Random rnd, List dimensions) { - - } - - @Override - public INDArray average(INDArray target, INDArray[] arrays) { - return null; - } - - @Override - public INDArray average(INDArray[] arrays) { - return null; - } - - @Override - public INDArray average(Collection arrays) { - return null; - } - - @Override - public INDArray accumulate(INDArray target, INDArray... arrays) { - return null; - } - - @Override - public INDArray average(INDArray target, Collection arrays) { - return null; - } - - @Override - public INDArray create(DataBuffer data) { - return null; - } - - @Override - public INDArray create(DataBuffer data, long rows, long columns, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(DataBuffer data, int[] shape) { - return null; - } - - @Override - public INDArray create(DataBuffer data, int[] shape, int[] stride, long offset) { - return null; - } - - @Override - public INDArray create(float[][] floats) { - return null; - } - - @Override - public INDArray create(float[][] data, char ordering) { - return null; - } - - @Override - public INDArray create(float[] data, int[] shape, int[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer buffer, int[] shape, long offset) { - return null; - } - - @Override - public INDArray create(int[] shape, char ordering) { - return null; - } - - @Override - public INDArray createUninitialized(int[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(DataBuffer data, int[] newShape, int[] newStride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(float[] data, int[] shape, long offset, Character order) { - return null; - } - - @Override - public INDArray create(float[] data, long rows, long columns, int[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(List list, int[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, long offset) { - return null; - } - - @Override - public INDArray create(double[] data, int[] shape, int[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray convertDataEx(DataTypeEx typeSrc, INDArray source, DataTypeEx typeDst) { - return null; - } - - @Override - public DataBuffer convertDataEx(DataTypeEx typeSrc, DataBuffer source, DataTypeEx typeDst) { - return null; - } - - @Override - public void convertDataEx(DataTypeEx typeSrc, DataBuffer source, DataTypeEx typeDst, DataBuffer target) { - - } - - @Override - public void convertDataEx(DataTypeEx typeSrc, Pointer source, DataTypeEx typeDst, Pointer target, long length) { - - } - - @Override - public void convertDataEx(DataTypeEx typeSrc, Pointer source, DataTypeEx typeDst, DataBuffer buffer) { - - } - - @Override - public INDArray createFromNpyPointer(Pointer pointer) { - return null; - } - - @Override - public INDArray createFromNpyHeaderPointer(Pointer pointer) { - return null; - } - - @Override - public INDArray createFromNpyFile(File file) { - return null; - } - - @Override - public Map createFromNpzFile(File file){return null; } - - @Override - public Pointer convertToNumpy(INDArray array) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, long[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long[] stride, long offset, char ordering) { - return null; - } - - @Override - public INDArray[] tear(INDArray tensor, int... dimensions) { - return new INDArray[0]; - } - - @Override - public INDArray sort(INDArray x, boolean descending) { - if (x.isScalar()) - return x; - - NativeOpsHolder.getInstance().getDeviceNativeOps().sort(null, - x.data().addressPointer(), (LongPointer) x.shapeInfoDataBuffer().addressPointer(), - null, null, - descending); - - return x; - } - - @Override - public INDArray sort(INDArray x, boolean descending, int... dimension) { - if (x.isScalar()) - return x; - - Arrays.sort(dimension); - Pair tadBuffers = Nd4j.getExecutioner().getTADManager().getTADOnlyShapeInfo(x, dimension); - - - NativeOpsHolder.getInstance().getDeviceNativeOps().sortTad(null, - x.data().addressPointer(), (LongPointer) x.shapeInfoDataBuffer().addressPointer(), - null, null, - new IntPointer(dimension), - dimension.length, - (LongPointer) tadBuffers.getFirst().addressPointer(), - new LongPointerWrapper(tadBuffers.getSecond().addressPointer()), - descending); - - - return x; - } - - @Override - public INDArray sortCooIndices(INDArray x) { - - if(x.getFormat() != SparseFormat.COO){ - throw new UnsupportedOperationException("Not a COO ndarray"); - } - BaseSparseNDArrayCOO array = (BaseSparseNDArrayCOO) x; - DataBuffer val = array.getValues(); - DataBuffer idx = array.getIndices(); - long length = val.length(); - int rank = array.underlyingRank(); - - NativeOpsHolder.getInstance().getDeviceNativeOps().sortCooIndices(null, (LongPointer) idx.addressPointer(), val.addressPointer(), length, rank); - - - return array; - } - - @Override - public INDArray create(float[] data, long[] shape, long offset, Character order) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, long offset, Character order) { - return null; - } - - @Override - public INDArray create(float[] data, long[] shape, char ordering) { - return null; - } - - @Override - public INDArray create(double[] data, long[] shape, char ordering) { - return null; - } - - - @Override - public INDArray empty(DataType type) { - throw new UnsupportedOperationException(); - } - - @Override - public INDArray create(Collection strings, long[] shape, char order) { - throw new UnsupportedOperationException(); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/DirectSparseInfoProvider.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/DirectSparseInfoProvider.java deleted file mode 100644 index 6409ee251..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/DirectSparseInfoProvider.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu; - -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.BaseSparseInfoProvider; -import org.nd4j.linalg.api.shape.Shape; -import org.nd4j.linalg.api.shape.SparseDescriptor; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author Audrey Loeffel - */ -public class DirectSparseInfoProvider extends BaseSparseInfoProvider { - - private Map sparseCache = new ConcurrentHashMap<>(); - private AtomicInteger counter = new AtomicInteger(0); - private static final int MAX_ENTRIES = 100; - - @Override - public DataBuffer createSparseInformation(int[] flags, long[] sparseOffsets, int[] hiddenDimensions, int underlyingRank) { - - SparseDescriptor descriptor = new SparseDescriptor(flags, sparseOffsets, hiddenDimensions, underlyingRank); - - if(!sparseCache.containsKey(descriptor)){ - if(counter.get() < MAX_ENTRIES){ - if(!sparseCache.containsKey(descriptor)){ - counter.incrementAndGet(); - DataBuffer buffer = Shape.createSparseInformation(flags, sparseOffsets, hiddenDimensions, underlyingRank); - sparseCache.put(descriptor, buffer); - return buffer; - } - } else { - return Shape.createSparseInformation(flags, sparseOffsets, hiddenDimensions, underlyingRank); - } - } - return sparseCache.get(descriptor); - } - - @Override - public void purgeCache() { - sparseCache = new ConcurrentHashMap<>(); - } - -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseBlasWrapper.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseBlasWrapper.java deleted file mode 100644 index de3096fc0..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseBlasWrapper.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu; - -import org.nd4j.linalg.factory.BaseSparseBlasWrapper; - -/** - * @author Audrey Loeffel - */ -public class SparseBlasWrapper extends BaseSparseBlasWrapper { -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCOO.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCOO.java deleted file mode 100644 index 25abb1af6..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCOO.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu; - -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCOO; - -/** - * @author Audrey Loeffel - */ -public class SparseNDArrayCOO extends BaseSparseNDArrayCOO { - public SparseNDArrayCOO(double[] values, int[][] indices, long[] shape){ - super(values, indices, shape); - } - - public SparseNDArrayCOO(float[] values, int[][] indices, long[] shape) { - super(values, indices, shape); - } - - public SparseNDArrayCOO(double[] values, long[][] indices, long[] shape){ - super(values, indices, shape); - } - - public SparseNDArrayCOO(float[] values, long[][] indices, long[] shape) { - super(values, indices, shape); - } - - public SparseNDArrayCOO(DataBuffer values, DataBuffer indices, long[] shape){ - super(values, indices, shape); - } - - - public SparseNDArrayCOO(DataBuffer values, DataBuffer indices, long[] sparseOffsets, int[] flags, int[] hiddenDimensions, int underlyingRank, long[] shape){ - super(values, indices, sparseOffsets, flags, hiddenDimensions, underlyingRank, shape); - } - - public SparseNDArrayCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, long[] shape) { - super(values, indices, sparseInformation, shape); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java deleted file mode 100644 index f73f9dece..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu; - -import com.google.flatbuffers.FlatBufferBuilder; -import lombok.extern.slf4j.Slf4j; -import org.nd4j.linalg.api.blas.params.MMulTranspose; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.*; -import org.nd4j.linalg.api.shape.LongShapeDescriptor; - - -/** - * @author Audrey Loeffel - */ -@Slf4j -public class SparseNDArrayCSR extends BaseSparseNDArrayCSR { - -/** - * - * - * The length of the values and columns arrays is equal to the number of non-zero elements in A. - * The length of the pointerB and pointerE arrays is equal to the number of rows in A. - * @param data a double array that contains the non-zero element of the sparse matrix A - * @param columns Element i of the integer array columns is the number of the column in A that contains the i-th value - * in the values array. - * @param pointerB Element j of this integer array gives the index of the element in the values array that is first - * non-zero element in a row j of A. Note that this index is equal to pointerB(j) - pointerB(1)+1 . - * @param pointerE An integer array that contains row indices, such that pointerE(j)-pointerB(1) is the index of the - * element in the values array that is last non-zero element in a row j of A. - * @param shape Shape of the matrix A - */ - public SparseNDArrayCSR(double[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - - super(data, columns, pointerB, pointerE, shape); - } - public SparseNDArrayCSR(float[] data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - - super(data, columns, pointerB, pointerE, shape); - } - - public SparseNDArrayCSR(DataBuffer data, int[] columns, int[] pointerB, int[] pointerE, long[] shape) { - - super(data, columns, pointerB, pointerE, shape); - } - - @Override - public String getString(long index) { - return null; - } - - @Override - public INDArray assign(boolean value) { - return assign(value ? 1 : 0); - } - - @Override - public INDArray repeat(int dimension, long... repeats) { - return null; - } - - @Override - public INDArray mmul(INDArray other, MMulTranspose mMulTranspose) { - return null; - } - - @Override - public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, MMulTranspose transpose) { - return null; - } - - @Override - public INDArray mmuli(INDArray other, INDArray result, MMulTranspose transpose) { - return null; - } - - @Override - public long getLong(long index) { - return 0; - } - - @Override - public INDArray reshape(char order, int... newShape) { - return null; - } - - @Override - public INDArray reshape(char order, boolean enforceView, long... newShape) { - return null; - } - - @Override - public INDArray reshape(int[] shape) { - return null; - } - - @Override - public LongShapeDescriptor shapeDescriptor() { - return null; - } - - @Override - public int toFlatArray(FlatBufferBuilder builder) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public boolean isR() { - return false; - } - - @Override - public boolean isZ() { - return false; - } - - @Override - public boolean isB() { - return false; - } - - @Override - public INDArray castTo(DataType dataType) { - return null; - } - - @Override - public boolean all() { - return false; - } - - @Override - public boolean any() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean none() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean closeable() { - return false; - } - - @Override - public void close() { - - } - - @Override - public boolean isS() { - return false; - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuBlas.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuBlas.java deleted file mode 100644 index 870cb625e..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuBlas.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu.blas; - -import org.nd4j.nativeblas.SparseNd4jBlas; - -import static org.bytedeco.mkl.global.mkl_rt.*; - -/** - * @author Audrey Loeffel - */ -public class SparseCpuBlas extends SparseNd4jBlas { - - /** - * Converts a character - * to its proper enum - * for row (c) or column (f) ordering - * default is row major - */ - static int convertOrder(int from) { - switch (from) { - case 'c': - case 'C': - return CblasRowMajor; - case 'f': - case 'F': - return CblasColMajor; - default: - return CblasColMajor; - } - } - /** - * Converts a character to its proper enum - * t -> transpose - * n -> no transpose - * c -> conj - */ - static int convertTranspose(int from) { - switch (from) { - case 't': - case 'T': - return CblasTrans; - case 'n': - case 'N': - return CblasNoTrans; - case 'c': - case 'C': - return CblasConjTrans; - default: - return CblasNoTrans; - } - } - - /** - * Upper or lower - * U/u -> upper - * L/l -> lower - * - * Default is upper - */ - static int convertUplo(int from) { - switch (from) { - case 'u': - case 'U': - return CblasUpper; - case 'l': - case 'L': - return CblasLower; - default: - return CblasUpper; - } - } - - /** - * For diagonals: - * u/U -> unit - * n/N -> non unit - * - * Default: unit - */ - static int convertDiag(int from) { - switch (from) { - case 'u': - case 'U': - return CblasUnit; - case 'n': - case 'N': - return CblasNonUnit; - default: - return CblasUnit; - } - } - - /** - * Side of a matrix, left or right - * l /L -> left - * r/R -> right - * default: left - */ - static int convertSide(int from) { - switch (from) { - case 'l': - case 'L': - return CblasLeft; - case 'r': - case 'R': - return CblasRight; - default: - return CblasLeft; - } - } - - @Override - public void setMaxThreads(int num){ - MKL_Set_Num_Threads(num); - } - - @Override - public int getMaxThreads() { - return MKL_Get_Max_Threads(); - } - - @Override - public int getBlasVendorId() { - return Vendor.MKL.ordinal(); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLapack.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLapack.java deleted file mode 100644 index 5e7147dac..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLapack.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLapack; - -/** - * @author Audrey Loeffel - */ -public class SparseCpuLapack extends SparseBaseLapack { -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel1.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel1.java deleted file mode 100644 index 257e6dcbb..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel1.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLevel1; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.nativeblas.SparseNd4jBlas; -import org.bytedeco.javacpp.*; - -import static org.bytedeco.mkl.global.mkl_rt.*; - -/** - * @author Audrey Loeffel - */ -public class SparseCpuLevel1 extends SparseBaseLevel1 { - - // FIXME: int cast !!! - - private SparseNd4jBlas sparseNd4jBlas = (SparseNd4jBlas) Nd4j.sparseFactory().blas(); - - /** - * Computes the dot product of a compressed sparse double vector by a full-storage real vector. - * @param N The number of elements in x and indx - * @param X an sparse INDArray. Size at least N - * @param indx an Databuffer that Specifies the indices for the elements of x. Size at least N - * @param Y a dense INDArray. Size at least max(indx[i]) - * */ - @Override - protected double ddoti(long N, INDArray X, DataBuffer indx, INDArray Y) { - return cblas_ddoti((int) N, (DoublePointer) X.data().addressPointer(),(IntPointer) indx.addressPointer(), - (DoublePointer) Y.data().addressPointer()); - } - - /** - * Computes the dot product of a compressed sparse float vector by a full-storage real vector. - * @param N The number of elements in x and indx - * @param X an sparse INDArray. Size at least N - * @param indx an Databuffer that specifies the indices for the elements of x. Size at least N - * @param Y a dense INDArray. Size at least max(indx[i]) - * */ - @Override - protected double sdoti(long N, INDArray X, DataBuffer indx, INDArray Y) { - return cblas_sdoti((int) N, (FloatPointer) X.data().addressPointer(),(IntPointer) indx.addressPointer(), - (FloatPointer) Y.data().addressPointer()); - } - - @Override - protected double hdoti(long N, INDArray X, DataBuffer indx, INDArray Y) { - throw new UnsupportedOperationException(); - } - - /** - * Computes the Euclidean norm of a float vector - * @param N The number of elements in vector X - * @param X an INDArray - * @param incx the increment of X - * */ - @Override - protected double snrm2(long N, INDArray X, int incx){ - return cblas_snrm2((int) N, (FloatPointer) X.data().addressPointer(), incx); - } - - /** - * Computes the Euclidean norm of a double vector - * @param N The number of elements in vector X - * @param X an INDArray - * @param incx the increment of X - * */ - @Override - protected double dnrm2(long N, INDArray X, int incx){ - return cblas_dnrm2((int) N, (DoublePointer) X.data().addressPointer(), incx); - } - - @Override - protected double hnrm2(long N, INDArray X, int incx){ - throw new UnsupportedOperationException(); - } - - /** - * Compute the sum of magnitude of the double vector elements - * - * @param N The number of elements in vector X - * @param X a double vector - * @param incrx The increment of X - * @return the sum of magnitude of the vector elements - * */ - @Override - protected double dasum(long N, INDArray X, int incrx){ - return cblas_dasum((int) N, (DoublePointer) X.data().addressPointer(), incrx); - } - - /** - * Compute the sum of magnitude of the float vector elements - * - * @param N The number of elements in vector X - * @param X a float vector - * @param incrx The increment of X - * @return the sum of magnitude of the vector elements - * */ - @Override - protected double sasum(long N, INDArray X, int incrx){ - return cblas_sasum((int) N, (FloatPointer) X.data().addressPointer(), incrx); - } - - @Override - protected double hasum(long N, INDArray X, int incrx){ - throw new UnsupportedOperationException(); - } - - /** - * Find the index of the element with maximum absolute value - * - * @param N The number of elements in vector X - * @param X a vector - * @param incX The increment of X - * @return the index of the element with maximum absolute value - * */ - @Override - protected int isamax(long N, INDArray X, int incX) { - return (int) cblas_isamax((int) N, (FloatPointer) X.data().addressPointer(), incX); - } - /** - * Find the index of the element with maximum absolute value - * - * @param N The number of elements in vector X - * @param X a vector - * @param incX The increment of X - * @return the index of the element with maximum absolute value - * */ - @Override - protected int idamax(long N, INDArray X, int incX) { - return (int) cblas_idamax((int) N, (DoublePointer) X.data().addressPointer(), incX); - } - @Override - protected int ihamax(long N, INDArray X, int incX) { - throw new UnsupportedOperationException(); - } - - /** - * Find the index of the element with minimum absolute value - * - * @param N The number of elements in vector X - * @param X a vector - * @param incX The increment of X - * @return the index of the element with minimum absolute value - * */ - @Override - protected int isamin(long N, INDArray X, int incX) { - return (int) cblas_isamin((int) N, (FloatPointer) X.data().addressPointer(), incX); - } - - /** - * Find the index of the element with minimum absolute value - * - * @param N The number of elements in vector X - * @param X a vector - * @param incX The increment of X - * @return the index of the element with minimum absolute value - * */ - @Override - protected int idamin(long N, INDArray X, int incX) { - return (int) cblas_idamin((int) N, (DoublePointer) X.data().addressPointer(), incX); - } - @Override - protected int ihamin(long N, INDArray X, int incX) { - throw new UnsupportedOperationException(); - } - - /** - * Adds a scalar multiple of double compressed sparse vector to a full-storage vector. - * - * @param N The number of elements in vector X - * @param alpha - * @param X a sparse vector - * @param pointers A DataBuffer that specifies the indices for the elements of x. - * @param Y a dense vector - * - * */ - @Override - protected void daxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y){ - cblas_daxpyi((int) N, alpha, (DoublePointer) X.data().addressPointer(), (IntPointer) pointers.addressPointer(), - (DoublePointer) Y.data().addressPointer()); - } - - /** - * Adds a scalar multiple of float compressed sparse vector to a full-storage vector. - * - * @param N The number of elements in vector X - * @param alpha - * @param X a sparse vector - * @param pointers A DataBuffer that specifies the indices for the elements of x. - * @param Y a dense vector - * - * */ - @Override - protected void saxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y) { - cblas_saxpyi((int) N, (float) alpha, (FloatPointer) X.data().addressPointer(), (IntPointer) pointers.addressPointer(), - (FloatPointer) Y.data().addressPointer()); - } - - @Override - protected void haxpyi(long N, double alpha, INDArray X, DataBuffer pointers, INDArray Y){ - throw new UnsupportedOperationException(); - } - - /** - * Applies Givens rotation to sparse vectors one of which is in compressed form. - * - * @param N The number of elements in vectors X and Y - * @param X a double sparse vector - * @param indexes The indexes of the sparse vector - * @param Y a double full-storage vector - * @param c a scalar - * @param s a scalar - * */ - @Override - protected void droti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s) { - cblas_droti((int) N, (DoublePointer) X.data().addressPointer(), (IntPointer) indexes.addressPointer(), - (DoublePointer) Y.data().addressPointer(), c, s); - } - - /** - * Applies Givens rotation to sparse vectors one of which is in compressed form. - * - * @param N The number of elements in vectors X and Y - * @param X a float sparse vector - * @param indexes The indexes of the sparse vector - * @param Y a float full-storage vector - * @param c a scalar - * @param s a scalar - * */ - @Override - protected void sroti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s) { - cblas_sroti((int) N, (FloatPointer) X.data().addressPointer(), (IntPointer) indexes.addressPointer().capacity(X.columns()), - (FloatPointer) Y.data().addressPointer(), (float) c, (float) s); - } - - @Override - protected void hroti(long N, INDArray X, DataBuffer indexes, INDArray Y, double c, double s) { - throw new UnsupportedOperationException(); - } - - /** - * Computes the product of a double vector by a scalar. - * - * @param N The number of elements of the vector X - * @param a a scalar - * @param X a vector - * @param incx the increment of the vector X - * */ - @Override - protected void dscal(long N, double a, INDArray X, int incx) { - cblas_dscal((int) N, a, (DoublePointer) X.data().addressPointer(), incx); - } - - /** - * Computes the product of a float vector by a scalar. - * - * @param N The number of elements of the vector X - * @param a a scalar - * @param X a vector - * @param incx the increment of the vector X - * */ - @Override - protected void sscal(long N, double a, INDArray X, int incx) { - cblas_sscal((int) N, (float) a, (FloatPointer) X.data().addressPointer(), incx); - } - - @Override - protected void hscal(long N, double a, INDArray X, int incx) { - throw new UnsupportedOperationException(); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel2.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel2.java deleted file mode 100644 index 66282a8be..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel2.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu.blas; - -import org.bytedeco.javacpp.DoublePointer; -import org.bytedeco.javacpp.FloatPointer; -import org.bytedeco.javacpp.IntPointer; -import org.nd4j.linalg.api.blas.impl.SparseBaseLevel2; -import org.nd4j.linalg.api.buffer.DataBuffer; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.nativeblas.SparseNd4jBlas; - -import static org.bytedeco.mkl.global.mkl_rt.*; - -/** - * @author Audrey Loeffel - */ -public class SparseCpuLevel2 extends SparseBaseLevel2 { - private SparseNd4jBlas sparseNd4jBlas = (SparseNd4jBlas) Nd4j.sparseFactory().blas(); - // Mapping with Sparse Blas calls - - public void scoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, INDArray x, INDArray y){ - mkl_cspblas_scoogemv( - Character.toString(transA), - (IntPointer) Nd4j.createBuffer(new int[]{M}).addressPointer(), - (FloatPointer) values.addressPointer(), - (IntPointer) rowInd.addressPointer(), - (IntPointer) colInd.addressPointer(), - (IntPointer) Nd4j.createBuffer(new int[]{nnz}).addressPointer(), - (FloatPointer) x.data().addressPointer(), - (FloatPointer)y.data().addressPointer()); - } - public void dcoomv(char transA, int M, DataBuffer values, DataBuffer rowInd, DataBuffer colInd, int nnz, INDArray x, INDArray y){ - mkl_cspblas_dcoogemv( - Character.toString(transA), - (IntPointer) Nd4j.createBuffer(new int[]{M}).addressPointer(), - (DoublePointer) values.addressPointer(), - (IntPointer) rowInd.addressPointer(), - (IntPointer) colInd.addressPointer(), - (IntPointer) Nd4j.createBuffer(nnz).addressPointer(), - (DoublePointer) x.data().addressPointer(), - (DoublePointer)y.data().addressPointer()); - } -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel3.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel3.java deleted file mode 100644 index 734b897e7..000000000 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/blas/SparseCpuLevel3.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.cpu.nativecpu.blas; - -import org.nd4j.linalg.api.blas.impl.SparseBaseLevel3; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.nativeblas.SparseNd4jBlas; - -import static org.bytedeco.mkl.global.mkl_rt.*; - -/** - * @author Audrey Loeffel - */ -public class SparseCpuLevel3 extends SparseBaseLevel3 { - private SparseNd4jBlas sparseNd4jBlas = (SparseNd4jBlas) Nd4j.sparseFactory().blas(); - // TODO Mappings with Sparse Blas methods -} diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/resources/nd4j-native.properties b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/resources/nd4j-native.properties index 071cb4fd2..4690d54f6 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/resources/nd4j-native.properties +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/resources/nd4j-native.properties @@ -17,17 +17,15 @@ real.class.double = org.nd4j.linalg.cpu.NDArray complex.class.double = org.nd4j.linalg.cpu.nativecpu.complex.ComplexNDArray shapeinfoprovider = org.nd4j.linalg.cpu.nativecpu.DirectShapeInfoProvider -sparseinfoprovider = org.nd4j.linalg.cpu.nativecpu.DirectSparseInfoProvider constantsprovider = org.nd4j.linalg.cpu.nativecpu.cache.ConstantBuffersCache affinitymanager = org.nd4j.linalg.cpu.nativecpu.CpuAffinityManager memorymanager = org.nd4j.linalg.cpu.nativecpu.CpuMemoryManager dtype = float complex.double.class = org.nd4j.linalg.cpu.nativecpu.complex.ComplexDouble blas.ops = org.nd4j.linalg.cpu.nativecpu.BlasWrapper -sparseblas.ops = org.nd4j.linalg.cpu.nativecpu.SparseBlasWrapper + native.ops= org.nd4j.nativeblas.Nd4jCpu ndarrayfactory.class = org.nd4j.linalg.cpu.nativecpu.CpuNDArrayFactory -sparsendarrayfactory.class = org.nd4j.linalg.cpu.nativecpu.CpuSparseNDArrayFactory ndarray.order = c resourcemanager_state = false databufferfactory = org.nd4j.linalg.api.buffer.factory.DefaultDataBufferFactory diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/SparseNDArrayCOOTest.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/SparseNDArrayCOOTest.java deleted file mode 100644 index 026961361..000000000 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/SparseNDArrayCOOTest.java +++ /dev/null @@ -1,659 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Ignore; -import org.junit.Test; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCOO; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.factory.Nd4jBackend; -import org.nd4j.linalg.indexing.NDArrayIndex; -import org.nd4j.linalg.indexing.SpecifiedIndex; -import org.nd4j.linalg.util.ArrayUtil; - -import static org.junit.Assert.*; - -/** - * @author Audrey Loeffel - */ -@Slf4j -@Ignore // temporary ignored -public class SparseNDArrayCOOTest extends BaseNd4jTest { - - public SparseNDArrayCOOTest(Nd4jBackend b){ - super(b); - } - - @Override - public char ordering(){ - return 'c'; - } - - - - double[] data = {10, 1, 2, 3, 4, 5}; - long[] shape = {2, 2, 2}; - int[][] indices = new int[][] {new int[] {0, 0, 0, 1, 2, 2}, new int[] {0, 0, 1, 1, 1, 2}, - new int[] {1, 2, 2, 1, 0, 1}}; - - - @Test - public void shouldCreateSparseMatrix() { - // Commented out on removal of Nd4j createSparse methods - /*INDArray sparse = Nd4j.createSparseCOO(data, indices, shape); - assertArrayEquals(shape, sparse.shape()); - assertEquals(data.length, sparse.nnz()); - */ - } - - @Test - public void shouldPutScalar() { - // Commented out on removal of Nd4j createSparse methods - /* - INDArray sparse = Nd4j.createSparseCOO(new double[] {1, 2}, new int[][] {{0, 0}, {0, 2}}, new long[] {1, 3}); - sparse.putScalar(1, 3); - */ - } - - @Test - public void shouldntPutZero() { - // Commented out on removal of Nd4j createSparse methods - /* - INDArray sparse = Nd4j.createSparseCOO(new double[] {1, 2}, new int[][] {{0, 0}, {0, 2}}, new long[] {1, 3}); - int oldNNZ = sparse.nnz(); - sparse.putScalar(1, 0); - assertArrayEquals(new int[] {0, 2}, sparse.getVectorCoordinates().asInt()); - assertTrue(sparse.isRowVector()); - assertEquals(oldNNZ, sparse.nnz()); - */ - } - - @Test - public void shouldRemoveZero() { - // Commented out on removal of Nd4j createSparse methods - /* - INDArray sparse = Nd4j.createSparseCOO(new double[] {1, 2}, new int[][] {{0, 0}, {0, 2}}, new long[] {1, 3}); - sparse.putScalar(0, 0); - assertArrayEquals(new int[] {2}, sparse.getVectorCoordinates().asInt()); - */ - } - - @Test - public void shouldTakeViewInLeftTopCorner() { - // Test with dense ndarray - double[] data = {0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0}; - INDArray array = Nd4j.create(data, new int[] {5, 5}, 0, 'c'); - INDArray denseView = array.get(NDArrayIndex.interval(0, 2), NDArrayIndex.interval(0, 2)); - - // test with sparse : - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* - INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - - // subarray in the top right corner - BaseSparseNDArrayCOO sparseView = (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.interval(0, 2), - NDArrayIndex.interval(0, 2)); - assertArrayEquals(denseView.shape(), sparseView.shape()); - double[] currentValues = sparseView.data().asDouble(); - assertArrayEquals(values, currentValues, 1e-5); - assertArrayEquals(ArrayUtil.flatten(indices), sparseView.getUnderlyingIndices().asInt()); - assertEquals(0, sparseView.nnz()); - System.out.println(sparseView.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldTakeViewInLeftBottomCorner() { - - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* - INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - - BaseSparseNDArrayCOO sparseView = (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.interval(2, 5), - NDArrayIndex.interval(0, 2)); - assertEquals(1, sparseView.nnz()); - assertArrayEquals(new double[] {3}, sparseView.getIncludedValues().asDouble(), 1e-1); - assertArrayEquals(new int[] {0, 1}, sparseView.getIncludedIndices().asInt()); - - System.out.println(sparseView.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldTakeViewInRightTopCorner() { - - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - BaseSparseNDArrayCOO sparseView = (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.interval(0, 2), - NDArrayIndex.interval(2, 5)); - assertEquals(2, sparseView.nnz()); - assertArrayEquals(new double[] {1, 2}, sparseView.getIncludedValues().asDouble(), 1e-1); - assertArrayEquals(new int[] {0, 1, 1, 0}, sparseView.getIncludedIndices().asInt()); - - System.out.println(sparseView.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldTakeViewInTheMiddle() { - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - BaseSparseNDArrayCOO sparseView = (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.interval(1, 3), - NDArrayIndex.interval(1, 3)); - assertEquals(2, sparseView.nnz()); - assertArrayEquals(new double[] {2, 3}, sparseView.getIncludedValues().asDouble(), 1e-1); - assertArrayEquals(new int[] {0, 1, 1, 0}, sparseView.getIncludedIndices().asInt()); - - System.out.println(sparseView.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldGetFirstColumn() { - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - BaseSparseNDArrayCOO sparseView = - (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(0)); - assertEquals(0, sparseView.nnz()); - - System.out.println(sparseView.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldGetRowInTheMiddle() { - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - BaseSparseNDArrayCOO sparseView = - (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.point(2), NDArrayIndex.all()); - assertEquals(1, sparseView.nnz()); - assertArrayEquals(new int[] {0, 1}, sparseView.getIncludedIndices().asInt()); - assertArrayEquals(new double[] {3}, sparseView.getIncludedValues().asDouble(), 1e-1); - - System.out.println(sparseView.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldGetScalar() { - double[] values = {1, 2, 3, 4}; - int[][] indices = {{0, 3}, {1, 2}, {2, 1}, {3, 4}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray sparseNDArray = Nd4j.createSparseCOO(values, indices, new long[] {5, 5}); - BaseSparseNDArrayCOO sparseView = - (BaseSparseNDArrayCOO) sparseNDArray.get(NDArrayIndex.point(2), NDArrayIndex.point(1)); - assertEquals(1, sparseView.nnz()); - assertArrayEquals(new int[] {0, 0}, sparseView.getIncludedIndices().asInt()); - assertArrayEquals(new double[] {3}, sparseView.getIncludedValues().asDouble(), 1e-1); - assertTrue(sparseView.isScalar()); - */ - } - - @Test - public void shouldTakeView3dimensionArray() { - long[] shape = new long[] {2, 2, 2}; - double[] values = new double[] {2, 1, 4, 3}; - int[][] indices = new int[][] {{0, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}}; - - // Commented out on removal of Nd4j createSparse methods - /* INDArray array = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO view = - (BaseSparseNDArrayCOO) array.get(NDArrayIndex.all(), NDArrayIndex.point(0), NDArrayIndex.all()); - assertEquals(2, view.nnz()); - assertArrayEquals(new long[] {2, 2}, view.shape()); - assertArrayEquals(new int[] {0, 0, 1, 1}, view.getIncludedIndices().asInt()); - assertArrayEquals(new double[] {2, 1}, view.getIncludedValues().asDouble(), 1e-1); - - System.out.println(view.sparseInfoDataBuffer()); - */ - } - - @Test - public void shouldTakeViewOfView() { - long[] shape = new long[] {2, 2, 2}; - double[] values = new double[] {2, 1, 4, 3}; - int[][] indices = new int[][] {{0, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}}; - - // Commented out on removal of Nd4j createSparse methods - /* INDArray array = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO baseView = - (BaseSparseNDArrayCOO) array.get(NDArrayIndex.all(), NDArrayIndex.point(0), NDArrayIndex.all()); - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) baseView.get(NDArrayIndex.point(1), NDArrayIndex.all()); - assertEquals(1, view.nnz()); - assertArrayEquals(new long[] {1, 2}, view.shape()); - assertArrayEquals(new int[] {0, 1}, view.getIncludedIndices().asInt()); - assertArrayEquals(new double[] {1}, view.getIncludedValues().asDouble(), 1e-1); - */ - } - - @Test - public void shouldTakeViewOfView2() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 1}, {3, 1, 0}}; - - // Commented out on removal of Nd4j createSparse methods - /* INDArray array = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO baseView = (BaseSparseNDArrayCOO) array.get(NDArrayIndex.interval(1, 4), - NDArrayIndex.point(1), NDArrayIndex.all()); - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) baseView.get(NDArrayIndex.all(), NDArrayIndex.point(2)); - assertEquals(2, view.nnz()); - assertArrayEquals(new long[] {3, 1}, view.shape()); - assertArrayEquals(new int[] {0, 0, 1, 0}, view.getIncludedIndices().asInt()); - assertArrayEquals(new double[] {5, 7}, view.getIncludedValues().asDouble(), 1e-1); - assertTrue(view.isColumnVector()); - */ - } - - @Test - public void shouldGetWithSpecifiedIndexes() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 1}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /*INDArray array = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO newArray = (BaseSparseNDArrayCOO) array.get(new SpecifiedIndex(0, 3), - NDArrayIndex.all(), NDArrayIndex.all()); - assertEquals(4, newArray.nnz()); - assertArrayEquals(new double[] {1, 2, 8, 9}, newArray.getIncludedValues().asDouble(), 1e-1); - assertArrayEquals(new int[] {0, 0, 2, 0, 1, 1, 1, 0, 1, 1, 1, 0}, newArray.getIncludedIndices().asInt()); - */ - } - - @Test - public void shouldGetWithSpecifiedIndexes2() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray array = Nd4j.createSparseCOO(values, indices, shape); - - BaseSparseNDArrayCOO newArray = (BaseSparseNDArrayCOO) array.get(NDArrayIndex.interval(1, 4), - new SpecifiedIndex(0), new SpecifiedIndex(0, 2)); - assertEquals(2, newArray.nnz()); - assertArrayEquals(new double[] {3, 8}, newArray.getIncludedValues().asDouble(), 1e-1); - assertArrayEquals(new int[] {0, 0, 2, 1}, newArray.getIncludedIndices().asInt()); - */ - } - - @Test - public void specifiedIndexWithDenseArray() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - System.out.println(arr.toString()); - INDArray v = arr.get(NDArrayIndex.interval(1, 3), new SpecifiedIndex(0), - new SpecifiedIndex(0, 2)); - - System.out.println("v "); - System.out.println(v.toString()); - } - - @Test - public void newAxisWithSparseArray() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray array = Nd4j.createSparseCOO(values, indices, shape); - INDArray v = array.get(NDArrayIndex.point(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - */ - } - - @Test - public void nestedSparseViewWithNewAxis() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray array = Nd4j.createSparseCOO(values, indices, shape); - - System.out.println("\nTaking view (all, point(1), all"); - INDArray v = array.get(NDArrayIndex.all(), NDArrayIndex.point(1)); - System.out.println(v.toString()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println("Fixed dimension " + v.flags()); - System.out.println("sparse offsets " + v.sparseOffsets()); - System.out.println("hidden dimensions " + v.hiddenDimensions()); - System.out.println("number of hidden dimensions " + ((BaseSparseNDArrayCOO) v).getNumHiddenDimension()); - // shape 4 x 3 - - System.out.println("\nTaking view (all new axis"); - INDArray v1 = v.get(NDArrayIndex.all(), NDArrayIndex.newAxis()); - System.out.println(v1.toString()); - System.out.println(v1.shapeInfoDataBuffer()); - System.out.println("Fixed dimension " + v1.flags()); - System.out.println("sparse offsets " + v1.sparseOffsets()); - System.out.println("hidden dimensions " + v1.hiddenDimensions()); - System.out.println("number of hidden dimensions " + ((BaseSparseNDArrayCOO) v1).getNumHiddenDimension()); - // shape 4 x 1 x 3 - - System.out.println("\nTaking view (all new axis"); - v1 = v.get(NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.newAxis()); - System.out.println(v1.toString()); - System.out.println(v1.shapeInfoDataBuffer()); - System.out.println("Fixed dimension " + v1.flags()); - System.out.println("sparse offsets " + v1.sparseOffsets()); - System.out.println("hidden dimensions " + v1.hiddenDimensions()); - System.out.println("number of hidden dimensions " + ((BaseSparseNDArrayCOO) v1).getNumHiddenDimension()); - */ - } - - - @Test - public void nestedViewWithNewAxis() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - System.out.println(arr.toString()); - System.out.println(arr.shapeInfoDataBuffer()); - - System.out.println("\nTaking view (all, point(1), all"); - INDArray v = arr.get(NDArrayIndex.all(), NDArrayIndex.point(1)); - System.out.println(v.toString()); - System.out.println(v.shapeInfoDataBuffer()); - // shape 4 x 3 - - System.out.println("\nTaking view (all new axis"); - INDArray v1 = v.get(NDArrayIndex.all(), NDArrayIndex.newAxis()); - System.out.println(v1.toString()); - System.out.println(v1.shapeInfoDataBuffer()); - // shape 4 x 1 x 3 - - System.out.println("\nTaking view (all new axis"); - v1 = v1.get(NDArrayIndex.newAxis()); - System.out.println(v1.toString()); - System.out.println(v1.shapeInfoDataBuffer()); - // shape 4 x 3 - - } - - @Test - public void shouldTranslateViewIndexesToOriginal() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /*INDArray original = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) original.get(NDArrayIndex.all(), NDArrayIndex.point(1)); - int[] originalIdx = view.translateToPhysical(new int[] {0, 0}); - int[] exceptedIdx = new int[] {0, 1, 0}; - assertArrayEquals(exceptedIdx, originalIdx); - */ - } - - @Test - public void shouldTranslateViewIndexesToOriginal2() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray original = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) original.get(NDArrayIndex.all(), NDArrayIndex.newAxis(), - NDArrayIndex.point(1)); - assertArrayEquals(new int[] {0, 1, 0}, view.translateToPhysical(new int[] {0, 0, 0})); - assertArrayEquals(new int[] {1, 1, 1}, view.translateToPhysical(new int[] {1, 0, 1})); - */ - } - - @Test - public void shouldTranslateViewIndexesToOriginal3() { - long[] shape = new long[] {4, 2, 3, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2, 0}, {0, 1, 1, 1}, {1, 0, 0, 0}, {1, 0, 1, 0}, {1, 1, 2, 1}, - {2, 0, 1, 0}, {2, 1, 2, 0}, {3, 0, 2, 1}, {3, 1, 0, 1}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray original = Nd4j.createSparseCOO(values, indices, shape); - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) original.get(NDArrayIndex.all(), NDArrayIndex.newAxis(), - NDArrayIndex.point(1), NDArrayIndex.point(2)); - assertArrayEquals(new int[] {0, 1, 2, 0}, view.translateToPhysical(new int[] {0, 0, 0})); - assertArrayEquals(new int[] {1, 1, 2, 1}, view.translateToPhysical(new int[] {1, 0, 1})); - */ - } - - @Test - public void shouldTranslateViewWithPrependNewAxis() { - // TODO FIX get view with a new prepend axis - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* INDArray original = Nd4j.createSparseCOO(values, indices, shape); - - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) original.get(NDArrayIndex.newAxis(), NDArrayIndex.all(), - NDArrayIndex.point(1)); - System.out.println(view.getIncludedIndices()); - System.out.println(view.getIncludedValues()); - assertArrayEquals(new int[] {0, 1, 0}, view.translateToPhysical(new int[] {0, 0, 0})); - assertArrayEquals(new int[] {1, 1, 1}, view.translateToPhysical(new int[] {0, 1, 1})); - - int[] originalIdx = view.translateToPhysical(new int[] {0, 1, 2}); - int[] exceptedIdx = new int[] {1, 0, 2}; - assertArrayEquals(exceptedIdx, originalIdx); - */ - } - - @Test - public void shouldSortCOOIndices() { - long[] shape = new long[] {4, 3, 3}; - double[] values = new double[] {1}; - long[][] indices = new long[][] {{0, 0, 0}}; - // commented out on removal of createSparse methods from Nd4j - /* INDArray original = Nd4j.createSparseCOO(values, indices, shape); - original.putScalar(2, 2, 2, 3); - original.putScalar(1, 1, 1, 2); - - BaseSparseNDArrayCOO view = (BaseSparseNDArrayCOO) original.get(NDArrayIndex.all()); - int[] expectedIdx = new int[] {0, 0, 0, 1, 1, 1, 2, 2, 2}; - double[] expectedValues = new double[] {1, 2, 3}; - assertArrayEquals(expectedIdx, view.getIncludedIndices().asInt()); - assertArrayEquals(expectedValues, view.getIncludedValues().asDouble(), 1e-5); - assertTrue(view == original); - */ - } - - @Test - public void testWithDense() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - System.out.println(arr); - INDArray view = arr.get(NDArrayIndex.all(), NDArrayIndex.point(1)); - // System.out.println(view.shapeInfoDataBuffer()); - view = arr.get(NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.point(1), NDArrayIndex.all()); - System.out.println("view"); - System.out.println(view); - System.out.println(view.shapeInfoDataBuffer()); - } - - @Test - public void newAxisWithDenseArray() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - System.out.println(arr.toString()); - System.out.println(arr.shapeInfoDataBuffer()); - - System.out.println("\npoint 0"); - INDArray v = arr.get(NDArrayIndex.point(0)); - System.out.println(v.shapeInfoDataBuffer()); - // => shape 2 x 3 - - System.out.println("new axis, all, point 1"); - v = arr.get(NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.point(1)); - //System.out.println(v.toString()); - - v = arr.get(NDArrayIndex.interval(1, 4), NDArrayIndex.point(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.isView()); - // => shape 1 x 2 x 3 - - System.out.println("\npoint 0, newaxis"); - v = arr.get(NDArrayIndex.point(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.isView()); - // => shape 1 x 2 x 3 - - System.out.println("\n point 0, newaxis, newaxis"); - v = arr.get(NDArrayIndex.point(0), NDArrayIndex.newAxis(), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - // => shape 1 x 1 x 2 x 3 - - System.out.println("\n new axis, point 0, newaxis"); - v = arr.get(NDArrayIndex.newAxis(), NDArrayIndex.point(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - // => shape 1 x 1 x 2 x 3 - - System.out.println("\nget( new axis, point(0), point(0), new axis)"); - v = arr.get(NDArrayIndex.newAxis(), NDArrayIndex.point(0), NDArrayIndex.point(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.toString()); - // => shape 1 x 1 x 3 x 1 - - System.out.println("\nget( specified(1), specified(0), new axis)"); - v = arr.get(new SpecifiedIndex(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.toString()); - // => crash - - // System.out.println("\nget( new axis, point(0), new axis, point(0))"); - // v = arr.get( NDArrayIndex.newAxis(), NDArrayIndex.point(0), NDArrayIndex.newAxis(), NDArrayIndex.point(0)); - // System.out.println(v.shapeInfoDataBuffer()); - // System.out.println(v.toString()); - // => crash - - System.out.println("\n interval(0, 2), newaxis"); - v = arr.get(NDArrayIndex.interval(0, 2), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - // => shape 1 x 2 x 2 x 3 - new axis is added at the first position - - /* System.out.println("\n point 0 , all, new axis"); - v = arr.get( - NDArrayIndex.point(0), - NDArrayIndex.all(), - NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - */ - // => crash - - - } - - - @Test - public void testDenseNewAxisWithSpecifiedIdx() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - INDArray v = arr.get(new SpecifiedIndex(0), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.toString()); - } - - @Test - public void testDenseNewAxisWithSpecifiedIdx2() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - INDArray v = arr.get(NDArrayIndex.newAxis(), new SpecifiedIndex(0, 1), NDArrayIndex.all()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.toString()); - } - - @Test - public void testDenseNewAxisWithSpecifiedIdx3() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - INDArray v = arr.get(NDArrayIndex.point(0), NDArrayIndex.all(), NDArrayIndex.newAxis()); - System.out.println(v.shapeInfoDataBuffer()); - System.out.println(v.toString()); - } - - @Test - public void testDenseWithNewAxis() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - INDArray view = arr.get(NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.point(1)); - System.out.println(view); - } - - @Test - public void testWithPrependNewAxis() { - INDArray arr = Nd4j.rand(new int[] {4, 2, 3}); - System.out.println(arr.toString()); - System.out.println(arr.shapeInfoDataBuffer()); - - System.out.println("new axis, all, point 1"); - INDArray v = arr.get(NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.point(1)); - System.out.println(v.toString()); - System.out.println(v.shapeInfoDataBuffer()); - } - - @Test - public void binarySearch() { - long[] shape = new long[] {4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 2}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 2}, {2, 0, 1}, {2, 1, 2}, - {3, 0, 2}, {3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* BaseSparseNDArrayCOO array = (BaseSparseNDArrayCOO) Nd4j.createSparseCOO(values, indices, shape); - - assertEquals(0, array.reverseIndexes(0, 0, 2)); - assertEquals(7, array.reverseIndexes(3, 0, 2)); - assertEquals(8, array.reverseIndexes(3, 1, 0)); - */ - } - - @Test - public void rdmTest(){ - INDArray i = Nd4j.rand(new int[]{3, 3, 3}); - INDArray ii = i.get(NDArrayIndex.point(0), NDArrayIndex.all(), NDArrayIndex.all()); - System.out.println(ii); - System.out.println(ii.shapeInfoDataBuffer()); - - } - - @Test - public void tryToFindABugWithHiddenDim(){ - - long[] shape = new long[] {1, 4, 2, 3}; - double[] values = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; - int[][] indices = new int[][] {{0, 0, 0, 2}, {0, 0, 1, 1}, {0, 1, 0, 0}, {0, 1, 0, 1}, {0, 1, 1, 2}, {0, 2, 0, 1}, {0, 2, 1, 2}, - {0, 3, 0, 2}, {0, 3, 1, 0}}; - // Commented out on removal of Nd4j createSparse methods - /* BaseSparseNDArrayCOO array = (BaseSparseNDArrayCOO) Nd4j.createSparseCOO(values, indices, shape); - - BaseSparseNDArrayCOO view1 = (BaseSparseNDArrayCOO) array.get( NDArrayIndex.point(0), NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.point(0)); - System.out.println(view1.shapeInfoDataBuffer()); - System.out.println(view1.sparseInfoDataBuffer()); - - BaseSparseNDArrayCOO view2 = (BaseSparseNDArrayCOO) view1.get( NDArrayIndex.point(0), NDArrayIndex.newAxis(),NDArrayIndex.newAxis(), NDArrayIndex.point(0)); - System.out.println(view2.shapeInfoDataBuffer()); - System.out.println(view2.sparseInfoDataBuffer()); - */ - } -} - diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/SparseNDArrayCSRTest.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/SparseNDArrayCSRTest.java deleted file mode 100644 index 3e96704c9..000000000 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/SparseNDArrayCSRTest.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg; - -import org.junit.Ignore; -import org.junit.Test; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArrayCSR; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.factory.Nd4jBackend; -import org.nd4j.linalg.indexing.NDArrayIndex; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertTrue; - - -/** - * @author Audrey Loeffel - */ -@Ignore // temporary ignored -public class SparseNDArrayCSRTest extends BaseNd4jTest { - - public SparseNDArrayCSRTest(Nd4jBackend b){ - super(b); - } - - @Override - public char ordering(){ - return 'c'; - } - - /* - * [[1 -1 0 -3 0] - * [-2 4 0 0 0 ] - * [ 0 0 4 6 4 ] = A - * [-4 0 2 7 0 ] - * [ 0 8 0 0 -5]] - * */ - - // CSR representation of the matrix A according to https://software.intel.com/en-us/node/599835 - private double[] values = {1, -2, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, -5}; - private int[] columns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4}; - private int[] pointerB = {0, 3, 5, 8, 11}; - private int[] pointerE = {3, 5, 8, 11, 13}; - private long[] shape = {5, 5}; - - - @Test - public void shouldAddValueAtAGivenPosition() { - /* - * [[1 -1 0 -3 0] - * [-2 4 0 0 0 ] - * [ 0 3 4 6 4 ] = A' - * [-4 0 2 7 0 ] - * [ 0 8 0 0 -5]] - * */ - // commented out on removal of createSparse methods from Nd4j - /* - INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape); - if (sparseNDArray instanceof BaseSparseNDArrayCSR) { - BaseSparseNDArrayCSR sparseCSRArray = (BaseSparseNDArrayCSR) sparseNDArray; - sparseCSRArray.putScalar(2, 1, 3); - - double[] expectedValues = {1, -2, -3, -2, 5, 3, 4, 6, 4, -4, 2, 7, 8, -5}; - double[] expectedColumns = {0, 1, 3, 0, 1, 1, 2, 3, 4, 0, 2, 3, 1, 4}; - int[] expectedPointerB = {0, 3, 5, 9, 12}; - int[] expectedPointerE = {3, 5, 9, 12, 14}; - long[] expectedShape = {5, 5}; - - - assertArrayEquals(expectedValues, sparseCSRArray.getDoubleValues(), 0); - assertArrayEquals(expectedColumns, sparseCSRArray.getColumns(), 0); - assertArrayEquals(expectedPointerB, sparseCSRArray.getPointerBArray()); - assertArrayEquals(expectedPointerE, sparseCSRArray.getPointerEArray()); - assertArrayEquals(expectedShape, shape); - } - */ - } - - @Test - public void shouldReallocate() { - // commented out on removal of createSparse methods from Nd4j - /* - INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape); - if (sparseNDArray instanceof BaseSparseNDArrayCSR) { - BaseSparseNDArrayCSR sparseCSRArray = (BaseSparseNDArrayCSR) sparseNDArray; - int initialSize = sparseCSRArray.getDoubleValues().length; - - for (int i = 0; i < shape[0]; i++) { - for (int j = 0; j < shape[1]; j++) { - sparseCSRArray.putScalar(i, j, i + j); - } - } - int finalSize = sparseCSRArray.getDoubleValues().length; - assertTrue(finalSize > initialSize); - } - */ - } - - @Test - public void shouldReplaceValueAtAGivenPosition() { - /* - * [[1 -1 0 -3 0] - * [-2 4 0 0 0 ] - * [ 0 0 10 6 4] = A' - * [-4 0 2 7 0 ] - * [ 0 8 0 0 -5]] - * */ - // commented out on removal of createSparse methods from Nd4j - /* - INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape); - if (sparseNDArray instanceof BaseSparseNDArrayCSR) { - BaseSparseNDArrayCSR sparseCSRArray = (BaseSparseNDArrayCSR) sparseNDArray; - sparseCSRArray.putScalar(2, 2, 10); - - double[] expectedValues = {1, -2, -3, -2, 5, 10, 6, 4, -4, 2, 7, 8, -5}; - double[] expectedColumns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4}; - int[] expectedPointerB = {0, 3, 5, 8, 11}; - int[] expectedPointerE = {3, 5, 8, 11, 13}; - long[] expectedShape = {5, 5}; - - assertArrayEquals(expectedValues, sparseCSRArray.getDoubleValues(), 0); - assertArrayEquals(expectedColumns, sparseCSRArray.getColumns(), 0); - assertArrayEquals(expectedPointerB, sparseCSRArray.getPointerBArray()); - assertArrayEquals(expectedPointerE, sparseCSRArray.getPointerEArray()); - assertArrayEquals(expectedShape, shape); - } - */ - } - - @Test - public void shouldGetValueAtAGivenPosition() { - // Not yet implemented - } - - @Test - public void shouldBeEqualToDense() { - // Not yet implemented - } - - @Test - public void shouldGetAView() { - - double[] values = {1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, 5}; - int[] columns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4}; - int[] pointerB = {0, 3, 5, 8, 11}; - int[] pointerE = {3, 5, 8, 11, 13}; - - // Test with dense ndarray - double[] data = {1, -1, 0, -3, 0, -2, 5, 0, 0, 0, 0, 0, 4, 6, 4, -4, 0, 2, 7, 0, 0, 8, 0, 0, 5}; - INDArray array = Nd4j.create(data, new int[] {5, 5}, 0, 'c'); - INDArray denseView = array.get(NDArrayIndex.interval(1, 3), NDArrayIndex.interval(1, 3)); - - // test with sparse : - // commented out on removal of createSparse methods from Nd4j - /* - INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape); - - // subarray in the top right corner - BaseSparseNDArrayCSR sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(0, 3), - NDArrayIndex.interval(3, 5)); - assertArrayEquals(new int[] {0, 0, 1}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {2, 3, 6}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {3, 3, 8}, sparseView.getPointerEArray()); - - // subarray in the middle - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(1, 3), NDArrayIndex.interval(1, 3)); - assertArrayEquals(new int[] {0, 1}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {4, 5}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {5, 6}, sparseView.getPointerEArray()); - - // get the first row - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(0)); - assertArrayEquals(new int[] {0, 0, 0}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 3, 4, 8, 9}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {1, 4, 4, 9, 9}, sparseView.getPointerEArray()); - - // get several rows - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(0, 2), NDArrayIndex.all()); - assertArrayEquals(new int[] {0, 1, 3, 0, 1}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 3}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {3, 5}, sparseView.getPointerEArray()); - - // get a row in the middle - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.point(2), NDArrayIndex.all()); - assertArrayEquals(new int[] {2, 3, 4}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {5}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {8}, sparseView.getPointerEArray()); - - // get the first column - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(0)); - assertArrayEquals(new int[] {0, 0, 0}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 3, 4, 8, 9}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {1, 4, 4, 9, 9}, sparseView.getPointerEArray()); - - // get a column in the middle - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(2)); - assertArrayEquals(new int[] {0, 0}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 0, 5, 9, 10}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {0, 0, 6, 10, 10}, sparseView.getPointerEArray()); - - // get a part of the column in the middle - sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(1, 4), NDArrayIndex.point(2)); - assertArrayEquals(new int[] {0, 0}, sparseView.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 5, 9}, sparseView.getPointerBArray()); - assertArrayEquals(new int[] {0, 6, 10}, sparseView.getPointerEArray()); - */ - } - - @Test - public void shouldGetAViewFromView() { - double[] values = {1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, 5}; - int[] columns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4}; - int[] pointerB = {0, 3, 5, 8, 11}; - - // commented out on removal of createSparse methods from Nd4j - //INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape); - /* [0, -3, 0] - * sparseView = [0, 0, 0] subview = [[0,0], [4,6]] - * [4, 6, 4] - */ - - /*BaseSparseNDArrayCSR sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(0, 3), - NDArrayIndex.interval(2, 5)); - BaseSparseNDArrayCSR subview = - (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.interval(1, 3), NDArrayIndex.interval(0, 2)); - assertArrayEquals(new int[] {0, 1}, subview.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 5}, subview.getPointerBArray()); - assertArrayEquals(new int[] {0, 7}, subview.getPointerEArray()); - - // get the first column - subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.all(), NDArrayIndex.point(0)); - assertArrayEquals(new int[] {0}, subview.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0, 0, 5}, subview.getPointerBArray()); - assertArrayEquals(new int[] {0, 0, 6}, subview.getPointerEArray()); - - // get a column in the middle - subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.all(), NDArrayIndex.point(1)); - assertArrayEquals(new int[] {0, 0}, subview.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {2, 3, 6}, subview.getPointerBArray()); - assertArrayEquals(new int[] {3, 3, 7}, subview.getPointerEArray()); - - // get the first row - subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.point(0), NDArrayIndex.all()); - assertArrayEquals(new int[] {1}, subview.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {2}, subview.getPointerBArray()); - assertArrayEquals(new int[] {3}, subview.getPointerEArray()); - - // get a row in the middle - subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.point(1), NDArrayIndex.all()); - assertArrayEquals(new int[] {}, subview.getVectorCoordinates().asInt()); - assertArrayEquals(new int[] {0}, subview.getPointerBArray()); - assertArrayEquals(new int[] {0}, subview.getPointerEArray()); - */ - } -} diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCOOLevel1Test.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCOOLevel1Test.java deleted file mode 100644 index b22bcee7c..000000000 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCOOLevel1Test.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.nd4j.linalg.BaseNd4jTest; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArray; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.factory.Nd4jBackend; - -import static org.junit.Assert.assertEquals; - -/** - * @author Audrey Loeffel - */ -@Ignore // temporary ignored -@RunWith(Parameterized.class) -public class SparseCOOLevel1Test extends BaseNd4jTest { - - // vector = [1, 2, 0, 4] - private double[] data = {1, 2, 4}; - private int[][] indexes = new int[][] {{0, 0}, {0, 1}, {0, 3}}; - private long[] shape = {1, 4}; - - public SparseCOOLevel1Test(Nd4jBackend backend) { - super(backend); - } - - @Test - public void shouldComputeDot() { - // Commented out on removal of Nd4j createSparse methods - /*INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - //INDArray vec = Nd4j.create( new double[] {1 ,2, 3, 4}); - INDArray matrix = Nd4j.linspace(1, 4, 4, DataType.FLOAT).reshape(1, 4); - INDArray vec = matrix.getRow(0); - assertEquals(21, Nd4j.getBlasWrapper().dot(sparseVec, vec), 1e-1); - */ - } - - @Test - public void shouldComputeNrm2() { - // Commented out on removal of Nd4j createSparse methods - //INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - //assertEquals(Math.sqrt(21), Nd4j.getBlasWrapper().nrm2(sparseVec), 1e-1); - } - - @Test - public void shouldComputeAsum() { - // Commented out on removal of Nd4j createSparse methods - //INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - //assertEquals(7, Nd4j.getBlasWrapper().asum(sparseVec), 1e-1); - } - - @Test - public void shouldComputeIamax() { - // Commented out on removal of Nd4j createSparse methods - // INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - // assertEquals(2, Nd4j.getBlasWrapper().iamax(sparseVec), 1e-1); - } - - @Test - public void shouldComputeIamin() { - // Commented out on removal of Nd4j createSparse methods - // INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - // assertEquals(0, Nd4j.getBlasWrapper().level1().iamin(sparseVec), 1e-1); - } - - @Test - public void shouldComputeAxpy() { - // Commented out on removal of Nd4j createSparse methods - /* INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4}); - INDArray expected = Nd4j.create(new double[] {2, 4, 3, 8}); - Nd4j.getBlasWrapper().level1().axpy(vec.length(), 1, sparseVec, vec); - assertEquals(getFailureMessage(), expected, vec); - */ - } - - @Test - public void shouldComputeRot() { - - // try with dense vectors to get the expected result - - INDArray temp1 = Nd4j.create(new double[] {1, 2, 0, 4}); - INDArray temp2 = Nd4j.create(new double[] {1, 2, 3, 4}); - System.out.println("before: " + temp1.data() + " " + temp2.data()); - Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2); - System.out.println("after: " + temp1.data() + " " + temp2.data()); - - //before: [1.0,2.0,0.0,4.0] [1.0,2.0,3.0,4.0] - // after: [3.0,6.0,6.0,12.0] [-1.0,-2.0,3.0,-4.0] - - // Commented out on removal of Nd4j createSparse methods - /*INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4}); - Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2); - System.out.println(sparseVec.data() + " " + vec.data()); - //System.out.println("indexes: " + ((BaseSparseNDArray) sparseVec).getVectorCoordinates().toString()); - - INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 6, 12}, new int[] {0, 1, 2, 3}, - new int[] {0}, new int[] {4}, new long[] {1, 4}); - - INDArray expectedVec = Nd4j.create(new double[] {-1, -2, 3, -4}); - assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data()); - - assertEquals(getFailureMessage(), expectedVec, vec); - */ - // TODO FIXME - } - - @Test - public void shouldComputeRotWithFullVector() { - - // try with dense vectors to get the expected result - /* - INDArray temp1 = Nd4j.create( new double[] {1 ,2, 3, 4}); - INDArray temp2 = Nd4j.create( new double[] {1 ,2, 3, 4}); - System.out.println("before: " + temp1.data() + " " + temp2.data()); - Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2); - System.out.println("after: " + temp1.data() + " " + temp2.data()); - */ - //before: [1.0,2.0,3.0,4.0] [1.0,2.0,3.0,4.0] - // after: [3.0,6.0,0.0,12.0] [-1.0,-2.0,-3.0,-4.0] - - int[] cols = {0, 1, 2, 3}; - double[] values = {1, 2, 3, 4}; - // commented out on removal of createSparse methods from Nd4j - /* INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape); - INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4}); - Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2); - INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 9, 12}, new int[] {0, 1, 2, 3}, - new int[] {0}, new int[] {4}, new long[] {1, 4}); - INDArray expectedVec = Nd4j.create(new double[] {-1, -2, -3, -4}); - assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data()); - assertEquals(getFailureMessage(), expectedVec, vec); - if (expectedSparseVec.isSparse() && sparseVec.isSparse()) { - BaseSparseNDArray vec2 = ((BaseSparseNDArray) expectedSparseVec); - BaseSparseNDArray vecSparse2 = ((BaseSparseNDArray) sparseVec); - assertEquals(getFailureMessage(), vec2.getVectorCoordinates(), vecSparse2); - } - */ - } - - @Override - public char ordering() { - return 'c'; - } -} diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCOOLevel2Test.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCOOLevel2Test.java deleted file mode 100644 index 105089319..000000000 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCOOLevel2Test.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.nd4j.linalg.BaseNd4jTest; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.factory.Nd4jBackend; - -import static org.junit.Assert.assertEquals; - -/** - * @author Audrey Loeffel - */ -@Ignore // temporary ignored -@RunWith(Parameterized.class) -public class SparseCOOLevel2Test extends BaseNd4jTest { - - // matrix = [[1, 2], [0, 0]] - private double[] data = {1, 2}; - private int[][] indexes = new int[][] {{0, 0}, {0, 1}}; - private long[] shape = {2, 2}; - - public SparseCOOLevel2Test(Nd4jBackend backend) { - super(backend); - } - - @Test - public void testGemv() { - // commented out on removal of createSparse methods from Nd4j - /* INDArray array1 = Nd4j.createSparseCOO(data, indexes, shape); - INDArray array2 = Nd4j.linspace(1, 2, 2).reshape(2, 1); - - INDArray array3 = array1.mmul(array2); // should be [5, 0] - assertEquals(2, array3.length()); - assertEquals(5, array3.getFloat(0), 1e-5); - assertEquals(0, array3.getFloat(1), 1e-5); - */ - } - - - @Override - public char ordering() { - return 'c'; - } -} diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCSRLevel1Test.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCSRLevel1Test.java deleted file mode 100644 index 3c004a004..000000000 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/api/blas/SparseCSRLevel1Test.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015-2018 Skymind, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.nd4j.linalg.api.blas; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.nd4j.linalg.BaseNd4jTest; -import org.nd4j.linalg.api.buffer.DataType; -import org.nd4j.linalg.api.ndarray.BaseSparseNDArray; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.nd4j.linalg.factory.Nd4jBackend; - -import static org.junit.Assert.assertEquals; - -/** - * @author Audrey Loeffel - */ -@Ignore // temporary ignored -@RunWith(Parameterized.class) -public class SparseCSRLevel1Test extends BaseNd4jTest { - - private double[] data = {1, 2, 4}; - private int[] col = {0, 1, 3}; - private int[] pointerB = {0}; - private int[] pointerE = {4}; - private long[] shape = {1, 4}; - - public SparseCSRLevel1Test(Nd4jBackend backend) { - super(backend); - } - - @Test - public void shouldComputeDot() { - // commented out on removal of createSparse methods from Nd4j - //INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - //INDArray vec = Nd4j.create( new double[] {1 ,2, 3, 4}); - INDArray matrix = Nd4j.linspace(1, 4, 4).reshape(1, 4); - INDArray vec = matrix.getRow(0); - //assertEquals(21, Nd4j.getBlasWrapper().dot(sparseVec, vec), 1e-1); - } - - @Test - public void shouldComputeNrm2() { - // commented out on removal of createSparse methods from Nd4j - //INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - //assertEquals(Math.sqrt(21), Nd4j.getBlasWrapper().nrm2(sparseVec), 1e-1); - } - - @Test - public void shouldComputeAsum() { - // commented out on removal of createSparse methods from Nd4j - //INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - //assertEquals(7, Nd4j.getBlasWrapper().asum(sparseVec), 1e-1); - } - - @Test - public void shouldComputeIamax() { - // commented out on removal of createSparse methods from Nd4j - //INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - //assertEquals(2, Nd4j.getBlasWrapper().iamax(sparseVec), 1e-1); - } - - @Test - public void shouldComputeIamin() { - // commented out on removal of createSparse methods from Nd4j - //INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - //assertEquals(0, Nd4j.getBlasWrapper().level1().iamin(sparseVec), 1e-1); - } - - @Test - public void shouldComputeAxpy() { - // commented out on removal of createSparse methods from Nd4j - /* INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4}); - INDArray expected = Nd4j.create(new double[] {2, 4, 3, 8}); - Nd4j.getBlasWrapper().level1().axpy(vec.length(), 1, sparseVec, vec); - assertEquals(getFailureMessage(), expected, vec); - */ - } - - @Test - public void shouldComputeRot() { - - // try with dense vectors to get the expected result - - INDArray temp1 = Nd4j.create(new double[] {1, 2, 0, 4}); - INDArray temp2 = Nd4j.create(new double[] {1, 2, 3, 4}); - System.out.println("before: " + temp1.data() + " " + temp2.data()); - Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2); - System.out.println("after: " + temp1.data() + " " + temp2.data()); - - //before: [1.0,2.0,0.0,4.0] [1.0,2.0,3.0,4.0] - // after: [3.0,6.0,6.0,12.0] [-1.0,-2.0,3.0,-4.0] - - // commented out on removal of createSparse methods from Nd4j - /* INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape); - INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4}); - Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2); - System.out.println(sparseVec.data() + " " + vec.data()); - - //System.out.println("indexes: " + ((BaseSparseNDArray) sparseVec).getVectorCoordinates().toString()); - INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 6, 12}, new int[] {0, 1, 2, 3}, - new int[] {0}, new int[] {4}, new long[] {1, 4}); - INDArray expectedVec = Nd4j.create(new double[] {-1, -2, 3, -4}); - assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data()); - - assertEquals(getFailureMessage(), expectedVec, vec); - */ - // TODO fix it - } - - @Test - public void shouldComputeRotWithFullVector() { - - // try with dense vectors to get the expected result - /* - INDArray temp1 = Nd4j.create( new double[] {1 ,2, 3, 4}); - INDArray temp2 = Nd4j.create( new double[] {1 ,2, 3, 4}); - System.out.println("before: " + temp1.data() + " " + temp2.data()); - Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2); - System.out.println("after: " + temp1.data() + " " + temp2.data()); - */ - //before: [1.0,2.0,3.0,4.0] [1.0,2.0,3.0,4.0] - // after: [3.0,6.0,0.0,12.0] [-1.0,-2.0,-3.0,-4.0] - - int[] cols = {0, 1, 2, 3}; - double[] values = {1, 2, 3, 4}; - // commented out on removal of createSparse methods from Nd4j - /* INDArray sparseVec = Nd4j.createSparseCSR(values, cols, pointerB, pointerE, shape); - INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4}); - Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2); - - INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 9, 12}, new int[] {0, 1, 2, 3}, - new int[] {0}, new int[] {4}, new long[] {1, 4}); - INDArray expectedVec = Nd4j.create(new double[] {-1, -2, -3, -4}); - assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data()); - assertEquals(getFailureMessage(), expectedVec, vec); - if (expectedSparseVec.isSparse() && sparseVec.isSparse()) { - BaseSparseNDArray vec2 = ((BaseSparseNDArray) expectedSparseVec); - BaseSparseNDArray vecSparse2 = ((BaseSparseNDArray) sparseVec); - assertEquals(getFailureMessage(), vec2.getVectorCoordinates(), vecSparse2); - } - */ - } - - - @Override - public char ordering() { - return 'c'; - } -}