gpt4 book ai didi

mikera.vectorz.impl.ZeroVector类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 10:13:22 31 4
gpt4 key购买 nike

本文整理了Java中mikera.vectorz.impl.ZeroVector类的一些代码示例,展示了ZeroVector类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZeroVector类的具体详情如下:
包路径:mikera.vectorz.impl.ZeroVector
类名称:ZeroVector

ZeroVector介绍

[英]Specialised immutable vector containing nothing but zeros. This enables significant optimisations on operations involving zeros and composite arrays that have zero areas. Must have length 1 or more: use Vector0 instead for immutable length 0 vectors.
[中]只包含零的特殊不可变向量。这使得对涉及零和具有零面积的复合阵列的操作进行重大优化。长度必须为1或更多:对于不可变的长度为0的向量,请使用Vector0。

代码示例

代码示例来源:origin: net.mikera/vectorz

/**
 * Returns an immutable vector of zeros
 * @param dimensions
 * @return
 */
public static AVector immutableZeroVector(int dimensions) {
  return ZeroVector.create(dimensions);
}

代码示例来源:origin: net.mikera/vectorz

@Override
public AVector select(int... order) {
  for (int i: order) {
    checkIndex(i);
  }
  int n = order.length;
  if (n == length) return this;
  return createNew(n);
}

代码示例来源:origin: net.mikera/vectorz

public static ZeroVector createCached(int dimensions) {
  if (dimensions <= 0)
    throw new IllegalArgumentException("Can't create length "
        + dimensions + " ZeroVector. Use Vector0 instead");
  ZeroVector zv = tryCreate(dimensions);
  if (zv != null) return zv;
  zv = new ZeroVector(dimensions);
  last = zv;
  return zv;
}

代码示例来源:origin: mikera/vectorz

@Override
public AVector subVector(int offset, int length) {
  int len = checkRange(offset, length);
  if (length == 0) return Vector0.INSTANCE;
  if (length == len) return this;
  return ZeroVector.create(length);
}

代码示例来源:origin: mikera/vectorz

assertEquals(0, ZeroMatrix.create(1,2).elementPowSum(3), 0.0001); 
assertEquals(0, ZeroVector.create(2).elementAbsPowSum(1), 0.0001); 
assertEquals(0, ZeroVector.create(2).elementPowSum(3), 0.0001);

代码示例来源:origin: net.mikera/vectorz

@Override
public AVector innerProduct(AMatrix m) {
  checkLength(m.rowCount());
  return ZeroVector.create(m.columnCount());
}

代码示例来源:origin: mikera/vectorz

@Override
public ZeroVector multiplyCopy(AVector a) {
  checkSameLength(a);
  return this;
}

代码示例来源:origin: mikera/vectorz

@Test public void testArithmetic() {
  SparseColumnMatrix M=SparseColumnMatrix.create(3, 3);
  Vector v=Vector.of(-1,2,3);
  M.replaceColumn(1, v);
  assertEquals(4, M.elementSum(), 0.01);
  assertEquals(14, M.elementSquaredSum(), 0.01);
  assertEquals(-1, M.elementMin(), 0.01);
  assertEquals(3, M.elementMax(), 0.01);
  assertEquals(3, M.nonZeroCount());
  SparseRowMatrix N = SparseRowMatrix.create(3,3);
  v=Vector.of(4,5,6);
  N.replaceRow(1, v);
  M.add(N);                     // test add
  M.swapColumns(0,1);			// test swapColumns
  assertEquals(7, M.get(1,0), 0.01);
  SparseColumnMatrix M1 = SparseColumnMatrix.create(3, 3);
  Vector v1=Vector.of(-1,2,3);
  M1.replaceColumn(1, v1);
  int[] index = {0,2};
  double[] data = {7,8};
  SparseColumnMatrix M2 = SparseColumnMatrix.create(Vector.of(0,1,2),SparseIndexedVector.wrap(3, index, data),ZeroVector.createNew(3));
  M2.validate();
  
  M1.add(M2);                 // test adding SparseColumnMatrix
  assertEquals(2, M1.get(1,1), 0.01);
}

代码示例来源:origin: mikera/vectorz

@Override
public final ImmutableScalar slice(int i) {
  checkIndex(i);
  return ImmutableScalar.ZERO;
}

代码示例来源:origin: mikera/vectorz

@Override
public ZeroVector exactClone() {
  return new ZeroVector(length);
}

代码示例来源:origin: net.mikera/vectorz

/**
 * Create a ZeroVector with the specified number of dimensions
 * 
 * @param dimensions
 * @return
 */
public static ZeroVector create(int dimensions) {
  return createCached(dimensions);
}

代码示例来源:origin: net.mikera/vectorz

@Override
public AVector subVector(int offset, int length) {
  int len = checkRange(offset, length);
  if (length == 0) return Vector0.INSTANCE;
  if (length == len) return this;
  return ZeroVector.create(length);
}

代码示例来源:origin: mikera/vectorz

@Override
public AVector innerProduct(AMatrix m) {
  checkLength(m.rowCount());
  return ZeroVector.create(m.columnCount());
}

代码示例来源:origin: mikera/vectorz

@Override
public ZeroVector divideCopy(AVector a) {
  checkSameLength(a);
  return this;
}

代码示例来源:origin: net.mikera/vectorz

@Override
public double get(int i) {
  checkIndex(i);
  return 0.0;
}

代码示例来源:origin: net.mikera/vectorz

@Override
public ZeroVector exactClone() {
  return new ZeroVector(length);
}

代码示例来源:origin: mikera/vectorz

/**
 * Create a ZeroVector with the specified number of dimensions
 * 
 * @param dimensions
 * @return
 */
public static ZeroVector create(int dimensions) {
  return createCached(dimensions);
}

代码示例来源:origin: mikera/vectorz

/**
 * Returns an immutable vector of zeros
 * @param dimensions
 * @return
 */
public static AVector immutableZeroVector(int dimensions) {
  return ZeroVector.create(dimensions);
}

代码示例来源:origin: mikera/vectorz

@Override
public AVector select(int... order) {
  for (int i: order) {
    checkIndex(i);
  }
  int n = order.length;
  if (n == length) return this;
  return createNew(n);
}

代码示例来源:origin: net.mikera/vectorz

@Override
public ZeroVector divideCopy(AVector a) {
  checkSameLength(a);
  return this;
}

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com