faiss 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +1 -1
- data/ext/faiss/extconf.rb +1 -1
- data/ext/faiss/index.cpp +10 -14
- data/ext/faiss/numo.hpp +957 -833
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -2
- data/vendor/faiss/faiss/AutoTune.h +2 -2
- data/vendor/faiss/faiss/Clustering.cpp +2 -2
- data/vendor/faiss/faiss/Clustering.h +2 -2
- data/vendor/faiss/faiss/IVFlib.cpp +2 -2
- data/vendor/faiss/faiss/IVFlib.h +2 -2
- data/vendor/faiss/faiss/Index.cpp +6 -2
- data/vendor/faiss/faiss/Index.h +10 -3
- data/vendor/faiss/faiss/Index2Layer.cpp +2 -2
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +7 -7
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +14 -16
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +2 -2
- data/vendor/faiss/faiss/IndexBinary.cpp +13 -2
- data/vendor/faiss/faiss/IndexBinary.h +8 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +2 -7
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
- data/vendor/faiss/faiss/IndexFastScan.cpp +10 -14
- data/vendor/faiss/faiss/IndexFastScan.h +11 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +2 -3
- data/vendor/faiss/faiss/IndexFlat.h +2 -2
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +11 -2
- data/vendor/faiss/faiss/IndexFlatCodes.h +5 -2
- data/vendor/faiss/faiss/IndexHNSW.cpp +13 -6
- data/vendor/faiss/faiss/IndexHNSW.h +2 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
- data/vendor/faiss/faiss/IndexIDMap.h +5 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVF.h +5 -4
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +6 -7
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +71 -34
- data/vendor/faiss/faiss/IndexIVFFastScan.h +19 -2
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -33
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +2 -4
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -2
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +2 -3
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -2
- data/vendor/faiss/faiss/IndexLSH.cpp +2 -3
- data/vendor/faiss/faiss/IndexLSH.h +2 -2
- data/vendor/faiss/faiss/IndexLattice.cpp +2 -2
- data/vendor/faiss/faiss/IndexLattice.h +2 -2
- data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -2
- data/vendor/faiss/faiss/IndexNNDescent.h +2 -2
- data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
- data/vendor/faiss/faiss/IndexNSG.h +2 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +2 -2
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +2 -2
- data/vendor/faiss/faiss/IndexPQ.cpp +26 -26
- data/vendor/faiss/faiss/IndexPQ.h +2 -2
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +2 -5
- data/vendor/faiss/faiss/IndexPQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexPreTransform.cpp +2 -2
- data/vendor/faiss/faiss/IndexPreTransform.h +2 -2
- data/vendor/faiss/faiss/IndexRefine.cpp +41 -4
- data/vendor/faiss/faiss/IndexRefine.h +9 -2
- data/vendor/faiss/faiss/IndexReplicas.cpp +2 -2
- data/vendor/faiss/faiss/IndexReplicas.h +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +2 -2
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +2 -3
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/IndexShards.cpp +2 -2
- data/vendor/faiss/faiss/IndexShards.h +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +2 -2
- data/vendor/faiss/faiss/IndexShardsIVF.h +2 -2
- data/vendor/faiss/faiss/MatrixStats.cpp +2 -2
- data/vendor/faiss/faiss/MatrixStats.h +2 -2
- data/vendor/faiss/faiss/MetaIndexes.cpp +2 -3
- data/vendor/faiss/faiss/MetaIndexes.h +2 -2
- data/vendor/faiss/faiss/MetricType.h +2 -2
- data/vendor/faiss/faiss/VectorTransform.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +2 -2
- data/vendor/faiss/faiss/clone_index.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +44 -4
- data/vendor/faiss/faiss/cppcontrib/factory_tools.h +7 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +2 -2
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +2 -5
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +13 -13
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +6 -6
- data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +8 -7
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +6 -3
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +7 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +11 -4
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +51 -21
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +15 -5
- data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +2 -2
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +2 -2
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +2 -2
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +2 -3
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +54 -54
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +80 -78
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +51 -51
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +3 -3
- data/vendor/faiss/faiss/gpu/test/TestGpuResidualQuantizer.cpp +70 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +74 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +2 -2
- data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +79 -11
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +17 -5
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +2 -2
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +2 -2
- data/vendor/faiss/faiss/impl/FaissAssert.h +2 -2
- data/vendor/faiss/faiss/impl/FaissException.cpp +2 -2
- data/vendor/faiss/faiss/impl/FaissException.h +2 -3
- data/vendor/faiss/faiss/impl/HNSW.cpp +24 -19
- data/vendor/faiss/faiss/impl/HNSW.h +12 -2
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +2 -2
- data/vendor/faiss/faiss/impl/NNDescent.cpp +2 -2
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +27 -21
- data/vendor/faiss/faiss/impl/NSG.h +20 -8
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +2 -2
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +2 -2
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +2 -4
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +2 -36
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +3 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +2 -2
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +2 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +2 -2
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +2 -2
- data/vendor/faiss/faiss/impl/code_distance/code_distance-sve.h +440 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +55 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +2 -5
- data/vendor/faiss/faiss/impl/index_read_utils.h +2 -2
- data/vendor/faiss/faiss/impl/index_write.cpp +2 -6
- data/vendor/faiss/faiss/impl/io.cpp +2 -2
- data/vendor/faiss/faiss/impl/io.h +2 -2
- data/vendor/faiss/faiss/impl/io_macros.h +2 -9
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +2 -3
- data/vendor/faiss/faiss/impl/kmeans1d.h +2 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +2 -3
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/platform_macros.h +12 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +2 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +2 -2
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +2 -2
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +3 -3
- data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +2 -2
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +18 -18
- data/vendor/faiss/faiss/index_factory.cpp +20 -21
- data/vendor/faiss/faiss/index_factory.h +2 -2
- data/vendor/faiss/faiss/index_io.h +2 -2
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +2 -2
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +2 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +2 -2
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedLists.h +2 -2
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +2 -2
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +2 -2
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +2 -3
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +2 -2
- data/vendor/faiss/faiss/python/python_callbacks.cpp +2 -2
- data/vendor/faiss/faiss/python/python_callbacks.h +2 -2
- data/vendor/faiss/faiss/utils/AlignedTable.h +5 -3
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +2 -2
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +11 -7
- data/vendor/faiss/faiss/utils/NeuralNet.h +2 -2
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +2 -2
- data/vendor/faiss/faiss/utils/WorkerThread.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/generic.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +2 -2
- data/vendor/faiss/faiss/utils/bf16.h +2 -2
- data/vendor/faiss/faiss/utils/distances.cpp +191 -2
- data/vendor/faiss/faiss/utils/distances.h +3 -3
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +2 -2
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +2 -2
- data/vendor/faiss/faiss/utils/distances_simd.cpp +502 -3
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +2 -2
- data/vendor/faiss/faiss/utils/extra_distances.cpp +2 -3
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-arm.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +2 -2
- data/vendor/faiss/faiss/utils/fp16-inl.h +2 -2
- data/vendor/faiss/faiss/utils/fp16.h +2 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming.cpp +2 -3
- data/vendor/faiss/faiss/utils/hamming.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +490 -0
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +2 -2
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +5 -2
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +5 -5
- data/vendor/faiss/faiss/utils/ordered_key_value.h +2 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/prefetch.h +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +2 -2
- data/vendor/faiss/faiss/utils/quantize_lut.h +2 -2
- data/vendor/faiss/faiss/utils/random.cpp +2 -2
- data/vendor/faiss/faiss/utils/random.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
- data/vendor/faiss/faiss/utils/simdlib_ppc64.h +2 -2
- data/vendor/faiss/faiss/utils/sorting.cpp +2 -2
- data/vendor/faiss/faiss/utils/sorting.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +2 -2
- data/vendor/faiss/faiss/utils/utils.cpp +7 -7
- data/vendor/faiss/faiss/utils/utils.h +4 -3
- metadata +9 -10
data/ext/faiss/numo.hpp
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* Numo.hpp v0.
|
2
|
+
* Numo.hpp v0.2.0
|
3
3
|
* https://github.com/ankane/numo.hpp
|
4
4
|
* BSD-2-Clause License
|
5
5
|
*/
|
@@ -10,858 +10,982 @@
|
|
10
10
|
#include <numo/narray.h>
|
11
11
|
|
12
12
|
namespace numo {
|
13
|
-
class NArray {
|
14
|
-
public:
|
15
|
-
NArray(VALUE v) {
|
16
|
-
construct_value(this->dtype(), v);
|
17
|
-
}
|
18
|
-
|
19
|
-
NArray(Rice::Object o) {
|
20
|
-
construct_value(this->dtype(), o.value());
|
21
|
-
}
|
22
|
-
|
23
|
-
VALUE value() const {
|
24
|
-
return this->_value;
|
25
|
-
}
|
26
|
-
|
27
|
-
size_t ndim() const {
|
28
|
-
return RNARRAY_NDIM(this->_value);
|
29
|
-
}
|
30
|
-
|
31
|
-
size_t* shape() const {
|
32
|
-
return RNARRAY_SHAPE(this->_value);
|
33
|
-
}
|
34
|
-
|
35
|
-
size_t size() const {
|
36
|
-
return RNARRAY_SIZE(this->_value);
|
37
|
-
}
|
38
|
-
|
39
|
-
bool is_contiguous() const {
|
40
|
-
return nary_check_contiguous(this->_value) == Qtrue;
|
41
|
-
}
|
42
|
-
|
43
|
-
operator Rice::Object() const {
|
44
|
-
return Rice::Object(this->_value);
|
45
|
-
}
|
46
|
-
|
47
|
-
const void* read_ptr() {
|
48
|
-
if (!is_contiguous()) {
|
49
|
-
this->_value = nary_dup(this->_value);
|
50
|
-
}
|
51
|
-
return nary_get_pointer_for_read(this->_value) + nary_get_offset(this->_value);
|
52
|
-
}
|
53
|
-
|
54
|
-
void* write_ptr() {
|
55
|
-
return nary_get_pointer_for_write(this->_value);
|
56
|
-
}
|
57
|
-
|
58
|
-
protected:
|
59
|
-
NArray() { }
|
60
|
-
|
61
|
-
void construct_value(VALUE dtype, VALUE v) {
|
62
|
-
this->_value = rb_funcall(dtype, rb_intern("cast"), 1, v);
|
63
|
-
}
|
64
|
-
|
65
|
-
void construct_shape(VALUE dtype, std::initializer_list<size_t> shape) {
|
66
|
-
// rb_narray_new doesn't modify shape, but not marked as const
|
67
|
-
this->_value = rb_narray_new(dtype, shape.size(), const_cast<size_t*>(shape.begin()));
|
68
|
-
}
|
69
|
-
|
70
|
-
VALUE _value;
|
71
|
-
|
72
|
-
private:
|
73
|
-
VALUE dtype() {
|
74
|
-
return numo_cNArray;
|
75
|
-
}
|
76
|
-
};
|
77
|
-
|
78
|
-
class SFloat: public NArray {
|
79
|
-
public:
|
80
|
-
SFloat(VALUE v) {
|
81
|
-
construct_value(this->dtype(), v);
|
82
|
-
}
|
83
|
-
|
84
|
-
SFloat(Rice::Object o) {
|
85
|
-
construct_value(this->dtype(), o.value());
|
86
|
-
}
|
87
|
-
|
88
|
-
SFloat(std::initializer_list<size_t> shape) {
|
89
|
-
construct_shape(this->dtype(), shape);
|
90
|
-
}
|
91
|
-
|
92
|
-
const float* read_ptr() {
|
93
|
-
return reinterpret_cast<const float*>(NArray::read_ptr());
|
94
|
-
}
|
95
|
-
|
96
|
-
float* write_ptr() {
|
97
|
-
return reinterpret_cast<float*>(NArray::write_ptr());
|
98
|
-
}
|
99
|
-
|
100
|
-
private:
|
101
|
-
VALUE dtype() {
|
102
|
-
return numo_cSFloat;
|
103
|
-
}
|
104
|
-
};
|
105
|
-
|
106
|
-
class DFloat: public NArray {
|
107
|
-
public:
|
108
|
-
DFloat(VALUE v) {
|
109
|
-
construct_value(this->dtype(), v);
|
110
|
-
}
|
111
|
-
|
112
|
-
DFloat(Rice::Object o) {
|
113
|
-
construct_value(this->dtype(), o.value());
|
114
|
-
}
|
115
|
-
|
116
|
-
DFloat(std::initializer_list<size_t> shape) {
|
117
|
-
construct_shape(this->dtype(), shape);
|
118
|
-
}
|
119
|
-
|
120
|
-
const double* read_ptr() {
|
121
|
-
return reinterpret_cast<const double*>(NArray::read_ptr());
|
122
|
-
}
|
123
|
-
|
124
|
-
double* write_ptr() {
|
125
|
-
return reinterpret_cast<double*>(NArray::write_ptr());
|
126
|
-
}
|
127
|
-
|
128
|
-
private:
|
129
|
-
VALUE dtype() {
|
130
|
-
return numo_cDFloat;
|
131
|
-
}
|
132
|
-
};
|
133
|
-
|
134
|
-
class Int8: public NArray {
|
135
|
-
public:
|
136
|
-
Int8(VALUE v) {
|
137
|
-
construct_value(this->dtype(), v);
|
138
|
-
}
|
139
|
-
|
140
|
-
Int8(Rice::Object o) {
|
141
|
-
construct_value(this->dtype(), o.value());
|
142
|
-
}
|
143
|
-
|
144
|
-
Int8(std::initializer_list<size_t> shape) {
|
145
|
-
construct_shape(this->dtype(), shape);
|
146
|
-
}
|
147
|
-
|
148
|
-
const int8_t* read_ptr() {
|
149
|
-
return reinterpret_cast<const int8_t*>(NArray::read_ptr());
|
150
|
-
}
|
151
|
-
|
152
|
-
int8_t* write_ptr() {
|
153
|
-
return reinterpret_cast<int8_t*>(NArray::write_ptr());
|
154
|
-
}
|
155
|
-
|
156
|
-
private:
|
157
|
-
VALUE dtype() {
|
158
|
-
return numo_cInt8;
|
159
|
-
}
|
160
|
-
};
|
161
|
-
|
162
|
-
class Int16: public NArray {
|
163
|
-
public:
|
164
|
-
Int16(VALUE v) {
|
165
|
-
construct_value(this->dtype(), v);
|
166
|
-
}
|
167
|
-
|
168
|
-
Int16(Rice::Object o) {
|
169
|
-
construct_value(this->dtype(), o.value());
|
170
|
-
}
|
171
|
-
|
172
|
-
Int16(std::initializer_list<size_t> shape) {
|
173
|
-
construct_shape(this->dtype(), shape);
|
174
|
-
}
|
175
|
-
|
176
|
-
const int16_t* read_ptr() {
|
177
|
-
return reinterpret_cast<const int16_t*>(NArray::read_ptr());
|
178
|
-
}
|
179
|
-
|
180
|
-
int16_t* write_ptr() {
|
181
|
-
return reinterpret_cast<int16_t*>(NArray::write_ptr());
|
182
|
-
}
|
183
|
-
|
184
|
-
private:
|
185
|
-
VALUE dtype() {
|
186
|
-
return numo_cInt16;
|
187
|
-
}
|
188
|
-
};
|
189
|
-
|
190
|
-
class Int32: public NArray {
|
191
|
-
public:
|
192
|
-
Int32(VALUE v) {
|
193
|
-
construct_value(this->dtype(), v);
|
194
|
-
}
|
195
|
-
|
196
|
-
Int32(Rice::Object o) {
|
197
|
-
construct_value(this->dtype(), o.value());
|
198
|
-
}
|
199
|
-
|
200
|
-
Int32(std::initializer_list<size_t> shape) {
|
201
|
-
construct_shape(this->dtype(), shape);
|
202
|
-
}
|
203
|
-
|
204
|
-
const int32_t* read_ptr() {
|
205
|
-
return reinterpret_cast<const int32_t*>(NArray::read_ptr());
|
206
|
-
}
|
207
|
-
|
208
|
-
int32_t* write_ptr() {
|
209
|
-
return reinterpret_cast<int32_t*>(NArray::write_ptr());
|
210
|
-
}
|
211
|
-
|
212
|
-
private:
|
213
|
-
VALUE dtype() {
|
214
|
-
return numo_cInt32;
|
215
|
-
}
|
216
|
-
};
|
217
|
-
|
218
|
-
class Int64: public NArray {
|
219
|
-
public:
|
220
|
-
Int64(VALUE v) {
|
221
|
-
construct_value(this->dtype(), v);
|
222
|
-
}
|
223
|
-
|
224
|
-
Int64(Rice::Object o) {
|
225
|
-
construct_value(this->dtype(), o.value());
|
226
|
-
}
|
227
|
-
|
228
|
-
Int64(std::initializer_list<size_t> shape) {
|
229
|
-
construct_shape(this->dtype(), shape);
|
230
|
-
}
|
231
|
-
|
232
|
-
const int64_t* read_ptr() {
|
233
|
-
return reinterpret_cast<const int64_t*>(NArray::read_ptr());
|
234
|
-
}
|
235
|
-
|
236
|
-
int64_t* write_ptr() {
|
237
|
-
return reinterpret_cast<int64_t*>(NArray::write_ptr());
|
238
|
-
}
|
239
|
-
|
240
|
-
private:
|
241
|
-
VALUE dtype() {
|
242
|
-
return numo_cInt64;
|
243
|
-
}
|
244
|
-
};
|
245
|
-
|
246
|
-
class UInt8: public NArray {
|
247
|
-
public:
|
248
|
-
UInt8(VALUE v) {
|
249
|
-
construct_value(this->dtype(), v);
|
250
|
-
}
|
251
|
-
|
252
|
-
UInt8(Rice::Object o) {
|
253
|
-
construct_value(this->dtype(), o.value());
|
254
|
-
}
|
255
|
-
|
256
|
-
UInt8(std::initializer_list<size_t> shape) {
|
257
|
-
construct_shape(this->dtype(), shape);
|
258
|
-
}
|
259
|
-
|
260
|
-
const uint8_t* read_ptr() {
|
261
|
-
return reinterpret_cast<const uint8_t*>(NArray::read_ptr());
|
262
|
-
}
|
263
|
-
|
264
|
-
uint8_t* write_ptr() {
|
265
|
-
return reinterpret_cast<uint8_t*>(NArray::write_ptr());
|
266
|
-
}
|
267
|
-
|
268
|
-
private:
|
269
|
-
VALUE dtype() {
|
270
|
-
return numo_cUInt8;
|
271
|
-
}
|
272
|
-
};
|
273
|
-
|
274
|
-
class UInt16: public NArray {
|
275
|
-
public:
|
276
|
-
UInt16(VALUE v) {
|
277
|
-
construct_value(this->dtype(), v);
|
278
|
-
}
|
279
|
-
|
280
|
-
UInt16(Rice::Object o) {
|
281
|
-
construct_value(this->dtype(), o.value());
|
282
|
-
}
|
283
|
-
|
284
|
-
UInt16(std::initializer_list<size_t> shape) {
|
285
|
-
construct_shape(this->dtype(), shape);
|
286
|
-
}
|
287
|
-
|
288
|
-
const uint16_t* read_ptr() {
|
289
|
-
return reinterpret_cast<const uint16_t*>(NArray::read_ptr());
|
290
|
-
}
|
291
|
-
|
292
|
-
uint16_t* write_ptr() {
|
293
|
-
return reinterpret_cast<uint16_t*>(NArray::write_ptr());
|
294
|
-
}
|
295
|
-
|
296
|
-
private:
|
297
|
-
VALUE dtype() {
|
298
|
-
return numo_cUInt16;
|
299
|
-
}
|
300
|
-
};
|
301
|
-
|
302
|
-
class UInt32: public NArray {
|
303
|
-
public:
|
304
|
-
UInt32(VALUE v) {
|
305
|
-
construct_value(this->dtype(), v);
|
306
|
-
}
|
307
|
-
|
308
|
-
UInt32(Rice::Object o) {
|
309
|
-
construct_value(this->dtype(), o.value());
|
310
|
-
}
|
311
|
-
|
312
|
-
UInt32(std::initializer_list<size_t> shape) {
|
313
|
-
construct_shape(this->dtype(), shape);
|
314
|
-
}
|
315
|
-
|
316
|
-
const uint32_t* read_ptr() {
|
317
|
-
return reinterpret_cast<const uint32_t*>(NArray::read_ptr());
|
318
|
-
}
|
319
|
-
|
320
|
-
uint32_t* write_ptr() {
|
321
|
-
return reinterpret_cast<uint32_t*>(NArray::write_ptr());
|
322
|
-
}
|
323
|
-
|
324
|
-
private:
|
325
|
-
VALUE dtype() {
|
326
|
-
return numo_cUInt32;
|
327
|
-
}
|
328
|
-
};
|
329
|
-
|
330
|
-
class UInt64: public NArray {
|
331
|
-
public:
|
332
|
-
UInt64(VALUE v) {
|
333
|
-
construct_value(this->dtype(), v);
|
334
|
-
}
|
335
|
-
|
336
|
-
UInt64(Rice::Object o) {
|
337
|
-
construct_value(this->dtype(), o.value());
|
338
|
-
}
|
339
|
-
|
340
|
-
UInt64(std::initializer_list<size_t> shape) {
|
341
|
-
construct_shape(this->dtype(), shape);
|
342
|
-
}
|
343
|
-
|
344
|
-
const uint64_t* read_ptr() {
|
345
|
-
return reinterpret_cast<const uint64_t*>(NArray::read_ptr());
|
346
|
-
}
|
347
|
-
|
348
|
-
uint64_t* write_ptr() {
|
349
|
-
return reinterpret_cast<uint64_t*>(NArray::write_ptr());
|
350
|
-
}
|
351
|
-
|
352
|
-
private:
|
353
|
-
VALUE dtype() {
|
354
|
-
return numo_cUInt64;
|
355
|
-
}
|
356
|
-
};
|
357
|
-
|
358
|
-
class SComplex: public NArray {
|
359
|
-
public:
|
360
|
-
SComplex(VALUE v) {
|
361
|
-
construct_value(this->dtype(), v);
|
362
|
-
}
|
363
|
-
|
364
|
-
SComplex(Rice::Object o) {
|
365
|
-
construct_value(this->dtype(), o.value());
|
366
|
-
}
|
367
13
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
}
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
}
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
14
|
+
class NArray {
|
15
|
+
public:
|
16
|
+
NArray(VALUE v) {
|
17
|
+
construct_value(this->dtype(), v);
|
18
|
+
}
|
19
|
+
|
20
|
+
NArray(Rice::Object o) {
|
21
|
+
construct_value(this->dtype(), o.value());
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE value() const {
|
25
|
+
return this->_value;
|
26
|
+
}
|
27
|
+
|
28
|
+
size_t ndim() const {
|
29
|
+
return RNARRAY_NDIM(this->_value);
|
30
|
+
}
|
31
|
+
|
32
|
+
size_t* shape() const {
|
33
|
+
return RNARRAY_SHAPE(this->_value);
|
34
|
+
}
|
35
|
+
|
36
|
+
size_t size() const {
|
37
|
+
return RNARRAY_SIZE(this->_value);
|
38
|
+
}
|
39
|
+
|
40
|
+
bool is_contiguous() const {
|
41
|
+
return nary_check_contiguous(this->_value) == Qtrue;
|
42
|
+
}
|
43
|
+
|
44
|
+
operator Rice::Object() const {
|
45
|
+
return Rice::Object(this->_value);
|
46
|
+
}
|
47
|
+
|
48
|
+
const void* read_ptr() {
|
49
|
+
if (!is_contiguous()) {
|
50
|
+
this->_value = nary_dup(this->_value);
|
51
|
+
}
|
52
|
+
return nary_get_pointer_for_read(this->_value) + nary_get_offset(this->_value);
|
53
|
+
}
|
54
|
+
|
55
|
+
void* write_ptr() {
|
56
|
+
return nary_get_pointer_for_write(this->_value);
|
57
|
+
}
|
58
|
+
|
59
|
+
protected:
|
60
|
+
NArray() { }
|
61
|
+
|
62
|
+
void construct_value(VALUE dtype, VALUE v) {
|
63
|
+
this->_value = rb_funcall(dtype, rb_intern("cast"), 1, v);
|
64
|
+
}
|
65
|
+
|
66
|
+
void construct_shape(VALUE dtype, std::initializer_list<size_t> shape) {
|
67
|
+
// rb_narray_new doesn't modify shape, but not marked as const
|
68
|
+
this->_value = rb_narray_new(dtype, shape.size(), const_cast<size_t*>(shape.begin()));
|
69
|
+
}
|
70
|
+
|
71
|
+
VALUE _value;
|
72
|
+
|
73
|
+
private:
|
74
|
+
VALUE dtype() {
|
75
|
+
return numo_cNArray;
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
class SFloat: public NArray {
|
80
|
+
public:
|
81
|
+
SFloat(VALUE v) {
|
82
|
+
construct_value(this->dtype(), v);
|
83
|
+
}
|
84
|
+
|
85
|
+
SFloat(Rice::Object o) {
|
86
|
+
construct_value(this->dtype(), o.value());
|
87
|
+
}
|
88
|
+
|
89
|
+
SFloat(std::initializer_list<size_t> shape) {
|
90
|
+
construct_shape(this->dtype(), shape);
|
91
|
+
}
|
92
|
+
|
93
|
+
const float* read_ptr() {
|
94
|
+
return reinterpret_cast<const float*>(NArray::read_ptr());
|
95
|
+
}
|
96
|
+
|
97
|
+
float* write_ptr() {
|
98
|
+
return reinterpret_cast<float*>(NArray::write_ptr());
|
99
|
+
}
|
100
|
+
|
101
|
+
private:
|
102
|
+
VALUE dtype() {
|
103
|
+
return numo_cSFloat;
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
class DFloat: public NArray {
|
108
|
+
public:
|
109
|
+
DFloat(VALUE v) {
|
110
|
+
construct_value(this->dtype(), v);
|
111
|
+
}
|
112
|
+
|
113
|
+
DFloat(Rice::Object o) {
|
114
|
+
construct_value(this->dtype(), o.value());
|
115
|
+
}
|
116
|
+
|
117
|
+
DFloat(std::initializer_list<size_t> shape) {
|
118
|
+
construct_shape(this->dtype(), shape);
|
119
|
+
}
|
120
|
+
|
121
|
+
const double* read_ptr() {
|
122
|
+
return reinterpret_cast<const double*>(NArray::read_ptr());
|
123
|
+
}
|
124
|
+
|
125
|
+
double* write_ptr() {
|
126
|
+
return reinterpret_cast<double*>(NArray::write_ptr());
|
127
|
+
}
|
128
|
+
|
129
|
+
private:
|
130
|
+
VALUE dtype() {
|
131
|
+
return numo_cDFloat;
|
132
|
+
}
|
133
|
+
};
|
134
|
+
|
135
|
+
class Int8: public NArray {
|
136
|
+
public:
|
137
|
+
Int8(VALUE v) {
|
138
|
+
construct_value(this->dtype(), v);
|
139
|
+
}
|
140
|
+
|
141
|
+
Int8(Rice::Object o) {
|
142
|
+
construct_value(this->dtype(), o.value());
|
143
|
+
}
|
144
|
+
|
145
|
+
Int8(std::initializer_list<size_t> shape) {
|
146
|
+
construct_shape(this->dtype(), shape);
|
147
|
+
}
|
148
|
+
|
149
|
+
const int8_t* read_ptr() {
|
150
|
+
return reinterpret_cast<const int8_t*>(NArray::read_ptr());
|
151
|
+
}
|
152
|
+
|
153
|
+
int8_t* write_ptr() {
|
154
|
+
return reinterpret_cast<int8_t*>(NArray::write_ptr());
|
155
|
+
}
|
156
|
+
|
157
|
+
private:
|
158
|
+
VALUE dtype() {
|
159
|
+
return numo_cInt8;
|
160
|
+
}
|
161
|
+
};
|
162
|
+
|
163
|
+
class Int16: public NArray {
|
164
|
+
public:
|
165
|
+
Int16(VALUE v) {
|
166
|
+
construct_value(this->dtype(), v);
|
167
|
+
}
|
168
|
+
|
169
|
+
Int16(Rice::Object o) {
|
170
|
+
construct_value(this->dtype(), o.value());
|
171
|
+
}
|
172
|
+
|
173
|
+
Int16(std::initializer_list<size_t> shape) {
|
174
|
+
construct_shape(this->dtype(), shape);
|
175
|
+
}
|
176
|
+
|
177
|
+
const int16_t* read_ptr() {
|
178
|
+
return reinterpret_cast<const int16_t*>(NArray::read_ptr());
|
179
|
+
}
|
180
|
+
|
181
|
+
int16_t* write_ptr() {
|
182
|
+
return reinterpret_cast<int16_t*>(NArray::write_ptr());
|
183
|
+
}
|
184
|
+
|
185
|
+
private:
|
186
|
+
VALUE dtype() {
|
187
|
+
return numo_cInt16;
|
188
|
+
}
|
189
|
+
};
|
190
|
+
|
191
|
+
class Int32: public NArray {
|
192
|
+
public:
|
193
|
+
Int32(VALUE v) {
|
194
|
+
construct_value(this->dtype(), v);
|
195
|
+
}
|
196
|
+
|
197
|
+
Int32(Rice::Object o) {
|
198
|
+
construct_value(this->dtype(), o.value());
|
199
|
+
}
|
200
|
+
|
201
|
+
Int32(std::initializer_list<size_t> shape) {
|
202
|
+
construct_shape(this->dtype(), shape);
|
203
|
+
}
|
204
|
+
|
205
|
+
const int32_t* read_ptr() {
|
206
|
+
return reinterpret_cast<const int32_t*>(NArray::read_ptr());
|
207
|
+
}
|
208
|
+
|
209
|
+
int32_t* write_ptr() {
|
210
|
+
return reinterpret_cast<int32_t*>(NArray::write_ptr());
|
211
|
+
}
|
212
|
+
|
213
|
+
private:
|
214
|
+
VALUE dtype() {
|
215
|
+
return numo_cInt32;
|
216
|
+
}
|
217
|
+
};
|
218
|
+
|
219
|
+
class Int64: public NArray {
|
220
|
+
public:
|
221
|
+
Int64(VALUE v) {
|
222
|
+
construct_value(this->dtype(), v);
|
223
|
+
}
|
224
|
+
|
225
|
+
Int64(Rice::Object o) {
|
226
|
+
construct_value(this->dtype(), o.value());
|
227
|
+
}
|
228
|
+
|
229
|
+
Int64(std::initializer_list<size_t> shape) {
|
230
|
+
construct_shape(this->dtype(), shape);
|
231
|
+
}
|
232
|
+
|
233
|
+
const int64_t* read_ptr() {
|
234
|
+
return reinterpret_cast<const int64_t*>(NArray::read_ptr());
|
235
|
+
}
|
236
|
+
|
237
|
+
int64_t* write_ptr() {
|
238
|
+
return reinterpret_cast<int64_t*>(NArray::write_ptr());
|
239
|
+
}
|
240
|
+
|
241
|
+
private:
|
242
|
+
VALUE dtype() {
|
243
|
+
return numo_cInt64;
|
244
|
+
}
|
245
|
+
};
|
246
|
+
|
247
|
+
class UInt8: public NArray {
|
248
|
+
public:
|
249
|
+
UInt8(VALUE v) {
|
250
|
+
construct_value(this->dtype(), v);
|
251
|
+
}
|
252
|
+
|
253
|
+
UInt8(Rice::Object o) {
|
254
|
+
construct_value(this->dtype(), o.value());
|
255
|
+
}
|
256
|
+
|
257
|
+
UInt8(std::initializer_list<size_t> shape) {
|
258
|
+
construct_shape(this->dtype(), shape);
|
259
|
+
}
|
260
|
+
|
261
|
+
const uint8_t* read_ptr() {
|
262
|
+
return reinterpret_cast<const uint8_t*>(NArray::read_ptr());
|
263
|
+
}
|
264
|
+
|
265
|
+
uint8_t* write_ptr() {
|
266
|
+
return reinterpret_cast<uint8_t*>(NArray::write_ptr());
|
267
|
+
}
|
268
|
+
|
269
|
+
private:
|
270
|
+
VALUE dtype() {
|
271
|
+
return numo_cUInt8;
|
272
|
+
}
|
273
|
+
};
|
274
|
+
|
275
|
+
class UInt16: public NArray {
|
276
|
+
public:
|
277
|
+
UInt16(VALUE v) {
|
278
|
+
construct_value(this->dtype(), v);
|
279
|
+
}
|
280
|
+
|
281
|
+
UInt16(Rice::Object o) {
|
282
|
+
construct_value(this->dtype(), o.value());
|
283
|
+
}
|
284
|
+
|
285
|
+
UInt16(std::initializer_list<size_t> shape) {
|
286
|
+
construct_shape(this->dtype(), shape);
|
287
|
+
}
|
288
|
+
|
289
|
+
const uint16_t* read_ptr() {
|
290
|
+
return reinterpret_cast<const uint16_t*>(NArray::read_ptr());
|
291
|
+
}
|
292
|
+
|
293
|
+
uint16_t* write_ptr() {
|
294
|
+
return reinterpret_cast<uint16_t*>(NArray::write_ptr());
|
295
|
+
}
|
296
|
+
|
297
|
+
private:
|
298
|
+
VALUE dtype() {
|
299
|
+
return numo_cUInt16;
|
300
|
+
}
|
301
|
+
};
|
302
|
+
|
303
|
+
class UInt32: public NArray {
|
304
|
+
public:
|
305
|
+
UInt32(VALUE v) {
|
306
|
+
construct_value(this->dtype(), v);
|
307
|
+
}
|
308
|
+
|
309
|
+
UInt32(Rice::Object o) {
|
310
|
+
construct_value(this->dtype(), o.value());
|
311
|
+
}
|
312
|
+
|
313
|
+
UInt32(std::initializer_list<size_t> shape) {
|
314
|
+
construct_shape(this->dtype(), shape);
|
315
|
+
}
|
316
|
+
|
317
|
+
const uint32_t* read_ptr() {
|
318
|
+
return reinterpret_cast<const uint32_t*>(NArray::read_ptr());
|
319
|
+
}
|
320
|
+
|
321
|
+
uint32_t* write_ptr() {
|
322
|
+
return reinterpret_cast<uint32_t*>(NArray::write_ptr());
|
323
|
+
}
|
324
|
+
|
325
|
+
private:
|
326
|
+
VALUE dtype() {
|
327
|
+
return numo_cUInt32;
|
328
|
+
}
|
329
|
+
};
|
330
|
+
|
331
|
+
class UInt64: public NArray {
|
332
|
+
public:
|
333
|
+
UInt64(VALUE v) {
|
334
|
+
construct_value(this->dtype(), v);
|
335
|
+
}
|
336
|
+
|
337
|
+
UInt64(Rice::Object o) {
|
338
|
+
construct_value(this->dtype(), o.value());
|
339
|
+
}
|
340
|
+
|
341
|
+
UInt64(std::initializer_list<size_t> shape) {
|
342
|
+
construct_shape(this->dtype(), shape);
|
343
|
+
}
|
344
|
+
|
345
|
+
const uint64_t* read_ptr() {
|
346
|
+
return reinterpret_cast<const uint64_t*>(NArray::read_ptr());
|
347
|
+
}
|
348
|
+
|
349
|
+
uint64_t* write_ptr() {
|
350
|
+
return reinterpret_cast<uint64_t*>(NArray::write_ptr());
|
351
|
+
}
|
352
|
+
|
353
|
+
private:
|
354
|
+
VALUE dtype() {
|
355
|
+
return numo_cUInt64;
|
356
|
+
}
|
357
|
+
};
|
358
|
+
|
359
|
+
class SComplex: public NArray {
|
360
|
+
public:
|
361
|
+
SComplex(VALUE v) {
|
362
|
+
construct_value(this->dtype(), v);
|
363
|
+
}
|
364
|
+
|
365
|
+
SComplex(Rice::Object o) {
|
366
|
+
construct_value(this->dtype(), o.value());
|
367
|
+
}
|
368
|
+
|
369
|
+
SComplex(std::initializer_list<size_t> shape) {
|
370
|
+
construct_shape(this->dtype(), shape);
|
371
|
+
}
|
372
|
+
|
373
|
+
private:
|
374
|
+
VALUE dtype() {
|
375
|
+
return numo_cSComplex;
|
376
|
+
}
|
377
|
+
};
|
378
|
+
|
379
|
+
class DComplex: public NArray {
|
380
|
+
public:
|
381
|
+
DComplex(VALUE v) {
|
382
|
+
construct_value(this->dtype(), v);
|
383
|
+
}
|
384
|
+
|
385
|
+
DComplex(Rice::Object o) {
|
386
|
+
construct_value(this->dtype(), o.value());
|
387
|
+
}
|
388
|
+
|
389
|
+
DComplex(std::initializer_list<size_t> shape) {
|
390
|
+
construct_shape(this->dtype(), shape);
|
391
|
+
}
|
392
|
+
|
393
|
+
private:
|
394
|
+
VALUE dtype() {
|
395
|
+
return numo_cDComplex;
|
396
|
+
}
|
397
|
+
};
|
398
|
+
|
399
|
+
class Bit: public NArray {
|
400
|
+
public:
|
401
|
+
Bit(VALUE v) {
|
402
|
+
construct_value(this->dtype(), v);
|
403
|
+
}
|
404
|
+
|
405
|
+
Bit(Rice::Object o) {
|
406
|
+
construct_value(this->dtype(), o.value());
|
407
|
+
}
|
408
|
+
|
409
|
+
Bit(std::initializer_list<size_t> shape) {
|
410
|
+
construct_shape(this->dtype(), shape);
|
411
|
+
}
|
412
|
+
|
413
|
+
private:
|
414
|
+
VALUE dtype() {
|
415
|
+
return numo_cBit;
|
416
|
+
}
|
417
|
+
};
|
418
|
+
|
419
|
+
class RObject: public NArray {
|
420
|
+
public:
|
421
|
+
RObject(VALUE v) {
|
422
|
+
construct_value(this->dtype(), v);
|
423
|
+
}
|
424
|
+
|
425
|
+
RObject(Rice::Object o) {
|
426
|
+
construct_value(this->dtype(), o.value());
|
427
|
+
}
|
428
|
+
|
429
|
+
RObject(std::initializer_list<size_t> shape) {
|
430
|
+
construct_shape(this->dtype(), shape);
|
431
|
+
}
|
432
|
+
|
433
|
+
const VALUE* read_ptr() {
|
434
|
+
return reinterpret_cast<const VALUE*>(NArray::read_ptr());
|
435
|
+
}
|
436
|
+
|
437
|
+
VALUE* write_ptr() {
|
438
|
+
return reinterpret_cast<VALUE*>(NArray::write_ptr());
|
439
|
+
}
|
440
|
+
|
441
|
+
private:
|
442
|
+
VALUE dtype() {
|
443
|
+
return numo_cRObject;
|
444
|
+
}
|
445
|
+
};
|
411
446
|
|
412
|
-
private:
|
413
|
-
VALUE dtype() {
|
414
|
-
return numo_cBit;
|
415
|
-
}
|
416
|
-
};
|
417
|
-
|
418
|
-
class RObject: public NArray {
|
419
|
-
public:
|
420
|
-
RObject(VALUE v) {
|
421
|
-
construct_value(this->dtype(), v);
|
422
|
-
}
|
423
|
-
|
424
|
-
RObject(Rice::Object o) {
|
425
|
-
construct_value(this->dtype(), o.value());
|
426
|
-
}
|
427
|
-
|
428
|
-
RObject(std::initializer_list<size_t> shape) {
|
429
|
-
construct_shape(this->dtype(), shape);
|
430
|
-
}
|
431
|
-
|
432
|
-
const VALUE* read_ptr() {
|
433
|
-
return reinterpret_cast<const VALUE*>(NArray::read_ptr());
|
434
|
-
}
|
435
|
-
|
436
|
-
VALUE* write_ptr() {
|
437
|
-
return reinterpret_cast<VALUE*>(NArray::write_ptr());
|
438
|
-
}
|
439
|
-
|
440
|
-
private:
|
441
|
-
VALUE dtype() {
|
442
|
-
return numo_cRObject;
|
443
|
-
}
|
444
|
-
};
|
445
447
|
}
|
446
448
|
|
447
449
|
namespace Rice::detail {
|
448
|
-
template<>
|
449
|
-
struct Type<numo::NArray>
|
450
|
-
{
|
451
|
-
static bool verify()
|
452
|
-
{
|
453
|
-
return true;
|
454
|
-
}
|
455
|
-
};
|
456
|
-
|
457
|
-
template<>
|
458
|
-
class From_Ruby<numo::NArray>
|
459
|
-
{
|
460
|
-
public:
|
461
|
-
numo::NArray convert(VALUE x)
|
462
|
-
{
|
463
|
-
return numo::NArray(x);
|
464
|
-
}
|
465
|
-
};
|
466
|
-
|
467
|
-
template<>
|
468
|
-
class To_Ruby<numo::NArray>
|
469
|
-
{
|
470
|
-
public:
|
471
|
-
VALUE convert(const numo::NArray& x) {
|
472
|
-
return x.value();
|
473
|
-
}
|
474
|
-
};
|
475
|
-
|
476
|
-
template<>
|
477
|
-
struct Type<numo::SFloat>
|
478
|
-
{
|
479
|
-
static bool verify()
|
480
|
-
{
|
481
|
-
return true;
|
482
|
-
}
|
483
|
-
};
|
484
|
-
|
485
|
-
template<>
|
486
|
-
class From_Ruby<numo::SFloat>
|
487
|
-
{
|
488
|
-
public:
|
489
|
-
numo::SFloat convert(VALUE x)
|
490
|
-
{
|
491
|
-
return numo::SFloat(x);
|
492
|
-
}
|
493
|
-
};
|
494
|
-
|
495
|
-
template<>
|
496
|
-
class To_Ruby<numo::SFloat>
|
497
|
-
{
|
498
|
-
public:
|
499
|
-
VALUE convert(const numo::SFloat& x) {
|
500
|
-
return x.value();
|
501
|
-
}
|
502
|
-
};
|
503
|
-
|
504
|
-
template<>
|
505
|
-
struct Type<numo::DFloat>
|
506
|
-
{
|
507
|
-
static bool verify()
|
508
|
-
{
|
509
|
-
return true;
|
510
|
-
}
|
511
|
-
};
|
512
|
-
|
513
|
-
template<>
|
514
|
-
class From_Ruby<numo::DFloat>
|
515
|
-
{
|
516
|
-
public:
|
517
|
-
numo::DFloat convert(VALUE x)
|
518
|
-
{
|
519
|
-
return numo::DFloat(x);
|
520
|
-
}
|
521
|
-
};
|
522
|
-
|
523
|
-
template<>
|
524
|
-
class To_Ruby<numo::DFloat>
|
525
|
-
{
|
526
|
-
public:
|
527
|
-
VALUE convert(const numo::DFloat& x) {
|
528
|
-
return x.value();
|
529
|
-
}
|
530
|
-
};
|
531
450
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
451
|
+
template<>
|
452
|
+
struct Type<numo::NArray>
|
453
|
+
{
|
454
|
+
static bool verify() { return true; }
|
455
|
+
};
|
456
|
+
|
457
|
+
template<>
|
458
|
+
class From_Ruby<numo::NArray>
|
459
|
+
{
|
460
|
+
public:
|
461
|
+
Convertible is_convertible(VALUE value) {
|
462
|
+
switch (rb_type(value))
|
536
463
|
{
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
464
|
+
case RUBY_T_DATA:
|
465
|
+
return Data_Type<numo::NArray>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
466
|
+
case RUBY_T_ARRAY:
|
467
|
+
return Convertible::Cast;
|
468
|
+
default:
|
469
|
+
return Convertible::None;
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
numo::NArray convert(VALUE x) {
|
474
|
+
return numo::NArray(x);
|
475
|
+
}
|
476
|
+
};
|
477
|
+
|
478
|
+
template<>
|
479
|
+
class To_Ruby<numo::NArray>
|
480
|
+
{
|
481
|
+
public:
|
482
|
+
VALUE convert(const numo::NArray& x) {
|
483
|
+
return x.value();
|
484
|
+
}
|
485
|
+
};
|
486
|
+
|
487
|
+
template<>
|
488
|
+
struct Type<numo::SFloat>
|
489
|
+
{
|
490
|
+
static bool verify() { return true; }
|
491
|
+
};
|
492
|
+
|
493
|
+
template<>
|
494
|
+
class From_Ruby<numo::SFloat>
|
495
|
+
{
|
496
|
+
public:
|
497
|
+
Convertible is_convertible(VALUE value) {
|
498
|
+
switch (rb_type(value))
|
546
499
|
{
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
}
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
500
|
+
case RUBY_T_DATA:
|
501
|
+
return Data_Type<numo::SFloat>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
502
|
+
case RUBY_T_ARRAY:
|
503
|
+
return Convertible::Cast;
|
504
|
+
default:
|
505
|
+
return Convertible::None;
|
506
|
+
}
|
507
|
+
}
|
508
|
+
|
509
|
+
numo::SFloat convert(VALUE x) {
|
510
|
+
return numo::SFloat(x);
|
511
|
+
}
|
512
|
+
};
|
513
|
+
|
514
|
+
template<>
|
515
|
+
class To_Ruby<numo::SFloat>
|
516
|
+
{
|
517
|
+
public:
|
518
|
+
VALUE convert(const numo::SFloat& x) {
|
519
|
+
return x.value();
|
520
|
+
}
|
521
|
+
};
|
522
|
+
|
523
|
+
template<>
|
524
|
+
struct Type<numo::DFloat>
|
525
|
+
{
|
526
|
+
static bool verify() { return true; }
|
527
|
+
};
|
528
|
+
|
529
|
+
template<>
|
530
|
+
class From_Ruby<numo::DFloat>
|
531
|
+
{
|
532
|
+
public:
|
533
|
+
Convertible is_convertible(VALUE value) {
|
534
|
+
switch (rb_type(value))
|
564
535
|
{
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
536
|
+
case RUBY_T_DATA:
|
537
|
+
return Data_Type<numo::DFloat>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
538
|
+
case RUBY_T_ARRAY:
|
539
|
+
return Convertible::Cast;
|
540
|
+
default:
|
541
|
+
return Convertible::None;
|
542
|
+
}
|
543
|
+
}
|
544
|
+
|
545
|
+
numo::DFloat convert(VALUE x) {
|
546
|
+
return numo::DFloat(x);
|
547
|
+
}
|
548
|
+
};
|
549
|
+
|
550
|
+
template<>
|
551
|
+
class To_Ruby<numo::DFloat>
|
552
|
+
{
|
553
|
+
public:
|
554
|
+
VALUE convert(const numo::DFloat& x) {
|
555
|
+
return x.value();
|
556
|
+
}
|
557
|
+
};
|
558
|
+
|
559
|
+
template<>
|
560
|
+
struct Type<numo::Int8>
|
561
|
+
{
|
562
|
+
static bool verify() { return true; }
|
563
|
+
};
|
564
|
+
|
565
|
+
template<>
|
566
|
+
class From_Ruby<numo::Int8>
|
567
|
+
{
|
568
|
+
public:
|
569
|
+
Convertible is_convertible(VALUE value) {
|
570
|
+
switch (rb_type(value))
|
574
571
|
{
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
}
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
572
|
+
case RUBY_T_DATA:
|
573
|
+
return Data_Type<numo::Int8>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
574
|
+
case RUBY_T_ARRAY:
|
575
|
+
return Convertible::Cast;
|
576
|
+
default:
|
577
|
+
return Convertible::None;
|
578
|
+
}
|
579
|
+
}
|
580
|
+
|
581
|
+
numo::Int8 convert(VALUE x) {
|
582
|
+
return numo::Int8(x);
|
583
|
+
}
|
584
|
+
};
|
585
|
+
|
586
|
+
template<>
|
587
|
+
class To_Ruby<numo::Int8>
|
588
|
+
{
|
589
|
+
public:
|
590
|
+
VALUE convert(const numo::Int8& x) {
|
591
|
+
return x.value();
|
592
|
+
}
|
593
|
+
};
|
594
|
+
|
595
|
+
template<>
|
596
|
+
struct Type<numo::Int16>
|
597
|
+
{
|
598
|
+
static bool verify() { return true; }
|
599
|
+
};
|
600
|
+
|
601
|
+
template<>
|
602
|
+
class From_Ruby<numo::Int16>
|
603
|
+
{
|
604
|
+
public:
|
605
|
+
Convertible is_convertible(VALUE value) {
|
606
|
+
switch (rb_type(value))
|
592
607
|
{
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
608
|
+
case RUBY_T_DATA:
|
609
|
+
return Data_Type<numo::Int16>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
610
|
+
case RUBY_T_ARRAY:
|
611
|
+
return Convertible::Cast;
|
612
|
+
default:
|
613
|
+
return Convertible::None;
|
614
|
+
}
|
615
|
+
}
|
616
|
+
|
617
|
+
numo::Int16 convert(VALUE x) {
|
618
|
+
return numo::Int16(x);
|
619
|
+
}
|
620
|
+
};
|
621
|
+
|
622
|
+
template<>
|
623
|
+
class To_Ruby<numo::Int16>
|
624
|
+
{
|
625
|
+
public:
|
626
|
+
VALUE convert(const numo::Int16& x) {
|
627
|
+
return x.value();
|
628
|
+
}
|
629
|
+
};
|
630
|
+
|
631
|
+
template<>
|
632
|
+
struct Type<numo::Int32>
|
633
|
+
{
|
634
|
+
static bool verify() { return true; }
|
635
|
+
};
|
636
|
+
|
637
|
+
template<>
|
638
|
+
class From_Ruby<numo::Int32>
|
639
|
+
{
|
640
|
+
public:
|
641
|
+
Convertible is_convertible(VALUE value) {
|
642
|
+
switch (rb_type(value))
|
602
643
|
{
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
}
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
644
|
+
case RUBY_T_DATA:
|
645
|
+
return Data_Type<numo::Int32>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
646
|
+
case RUBY_T_ARRAY:
|
647
|
+
return Convertible::Cast;
|
648
|
+
default:
|
649
|
+
return Convertible::None;
|
650
|
+
}
|
651
|
+
}
|
652
|
+
|
653
|
+
numo::Int32 convert(VALUE x) {
|
654
|
+
return numo::Int32(x);
|
655
|
+
}
|
656
|
+
};
|
657
|
+
|
658
|
+
template<>
|
659
|
+
class To_Ruby<numo::Int32>
|
660
|
+
{
|
661
|
+
public:
|
662
|
+
VALUE convert(const numo::Int32& x) {
|
663
|
+
return x.value();
|
664
|
+
}
|
665
|
+
};
|
666
|
+
|
667
|
+
template<>
|
668
|
+
struct Type<numo::Int64>
|
669
|
+
{
|
670
|
+
static bool verify() { return true; }
|
671
|
+
};
|
672
|
+
|
673
|
+
template<>
|
674
|
+
class From_Ruby<numo::Int64>
|
675
|
+
{
|
676
|
+
public:
|
677
|
+
Convertible is_convertible(VALUE value) {
|
678
|
+
switch (rb_type(value))
|
620
679
|
{
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
680
|
+
case RUBY_T_DATA:
|
681
|
+
return Data_Type<numo::Int64>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
682
|
+
case RUBY_T_ARRAY:
|
683
|
+
return Convertible::Cast;
|
684
|
+
default:
|
685
|
+
return Convertible::None;
|
686
|
+
}
|
687
|
+
}
|
688
|
+
|
689
|
+
numo::Int64 convert(VALUE x) {
|
690
|
+
return numo::Int64(x);
|
691
|
+
}
|
692
|
+
};
|
693
|
+
|
694
|
+
template<>
|
695
|
+
class To_Ruby<numo::Int64>
|
696
|
+
{
|
697
|
+
public:
|
698
|
+
VALUE convert(const numo::Int64& x) {
|
699
|
+
return x.value();
|
700
|
+
}
|
701
|
+
};
|
702
|
+
|
703
|
+
template<>
|
704
|
+
struct Type<numo::UInt8>
|
705
|
+
{
|
706
|
+
static bool verify() { return true; }
|
707
|
+
};
|
708
|
+
|
709
|
+
template<>
|
710
|
+
class From_Ruby<numo::UInt8>
|
711
|
+
{
|
712
|
+
public:
|
713
|
+
Convertible is_convertible(VALUE value) {
|
714
|
+
switch (rb_type(value))
|
630
715
|
{
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
}
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
716
|
+
case RUBY_T_DATA:
|
717
|
+
return Data_Type<numo::UInt8>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
718
|
+
case RUBY_T_ARRAY:
|
719
|
+
return Convertible::Cast;
|
720
|
+
default:
|
721
|
+
return Convertible::None;
|
722
|
+
}
|
723
|
+
}
|
724
|
+
|
725
|
+
numo::UInt8 convert(VALUE x) {
|
726
|
+
return numo::UInt8(x);
|
727
|
+
}
|
728
|
+
};
|
729
|
+
|
730
|
+
template<>
|
731
|
+
class To_Ruby<numo::UInt8>
|
732
|
+
{
|
733
|
+
public:
|
734
|
+
VALUE convert(const numo::UInt8& x) {
|
735
|
+
return x.value();
|
736
|
+
}
|
737
|
+
};
|
738
|
+
|
739
|
+
template<>
|
740
|
+
struct Type<numo::UInt16>
|
741
|
+
{
|
742
|
+
static bool verify() { return true; }
|
743
|
+
};
|
744
|
+
|
745
|
+
template<>
|
746
|
+
class From_Ruby<numo::UInt16>
|
747
|
+
{
|
748
|
+
public:
|
749
|
+
Convertible is_convertible(VALUE value) {
|
750
|
+
switch (rb_type(value))
|
648
751
|
{
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
752
|
+
case RUBY_T_DATA:
|
753
|
+
return Data_Type<numo::UInt16>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
754
|
+
case RUBY_T_ARRAY:
|
755
|
+
return Convertible::Cast;
|
756
|
+
default:
|
757
|
+
return Convertible::None;
|
758
|
+
}
|
759
|
+
}
|
760
|
+
|
761
|
+
numo::UInt16 convert(VALUE x) {
|
762
|
+
return numo::UInt16(x);
|
763
|
+
}
|
764
|
+
};
|
765
|
+
|
766
|
+
template<>
|
767
|
+
class To_Ruby<numo::UInt16>
|
768
|
+
{
|
769
|
+
public:
|
770
|
+
VALUE convert(const numo::UInt16& x) {
|
771
|
+
return x.value();
|
772
|
+
}
|
773
|
+
};
|
774
|
+
|
775
|
+
template<>
|
776
|
+
struct Type<numo::UInt32>
|
777
|
+
{
|
778
|
+
static bool verify() { return true; }
|
779
|
+
};
|
780
|
+
|
781
|
+
template<>
|
782
|
+
class From_Ruby<numo::UInt32>
|
783
|
+
{
|
784
|
+
public:
|
785
|
+
Convertible is_convertible(VALUE value) {
|
786
|
+
switch (rb_type(value))
|
658
787
|
{
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
}
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
788
|
+
case RUBY_T_DATA:
|
789
|
+
return Data_Type<numo::UInt32>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
790
|
+
case RUBY_T_ARRAY:
|
791
|
+
return Convertible::Cast;
|
792
|
+
default:
|
793
|
+
return Convertible::None;
|
794
|
+
}
|
795
|
+
}
|
796
|
+
|
797
|
+
numo::UInt32 convert(VALUE x) {
|
798
|
+
return numo::UInt32(x);
|
799
|
+
}
|
800
|
+
};
|
801
|
+
|
802
|
+
template<>
|
803
|
+
class To_Ruby<numo::UInt32>
|
804
|
+
{
|
805
|
+
public:
|
806
|
+
VALUE convert(const numo::UInt32& x) {
|
807
|
+
return x.value();
|
808
|
+
}
|
809
|
+
};
|
810
|
+
|
811
|
+
template<>
|
812
|
+
struct Type<numo::UInt64>
|
813
|
+
{
|
814
|
+
static bool verify() { return true; }
|
815
|
+
};
|
816
|
+
|
817
|
+
template<>
|
818
|
+
class From_Ruby<numo::UInt64>
|
819
|
+
{
|
820
|
+
public:
|
821
|
+
Convertible is_convertible(VALUE value) {
|
822
|
+
switch (rb_type(value))
|
676
823
|
{
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
824
|
+
case RUBY_T_DATA:
|
825
|
+
return Data_Type<numo::UInt64>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
826
|
+
case RUBY_T_ARRAY:
|
827
|
+
return Convertible::Cast;
|
828
|
+
default:
|
829
|
+
return Convertible::None;
|
830
|
+
}
|
831
|
+
}
|
832
|
+
|
833
|
+
numo::UInt64 convert(VALUE x) {
|
834
|
+
return numo::UInt64(x);
|
835
|
+
}
|
836
|
+
};
|
837
|
+
|
838
|
+
template<>
|
839
|
+
class To_Ruby<numo::UInt64>
|
840
|
+
{
|
841
|
+
public:
|
842
|
+
VALUE convert(const numo::UInt64& x) {
|
843
|
+
return x.value();
|
844
|
+
}
|
845
|
+
};
|
846
|
+
|
847
|
+
template<>
|
848
|
+
struct Type<numo::SComplex>
|
849
|
+
{
|
850
|
+
static bool verify() { return true; }
|
851
|
+
};
|
852
|
+
|
853
|
+
template<>
|
854
|
+
class From_Ruby<numo::SComplex>
|
855
|
+
{
|
856
|
+
public:
|
857
|
+
Convertible is_convertible(VALUE value) {
|
858
|
+
switch (rb_type(value))
|
686
859
|
{
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
}
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
860
|
+
case RUBY_T_DATA:
|
861
|
+
return Data_Type<numo::SComplex>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
862
|
+
case RUBY_T_ARRAY:
|
863
|
+
return Convertible::Cast;
|
864
|
+
default:
|
865
|
+
return Convertible::None;
|
866
|
+
}
|
867
|
+
}
|
868
|
+
|
869
|
+
numo::SComplex convert(VALUE x) {
|
870
|
+
return numo::SComplex(x);
|
871
|
+
}
|
872
|
+
};
|
873
|
+
|
874
|
+
template<>
|
875
|
+
class To_Ruby<numo::SComplex>
|
876
|
+
{
|
877
|
+
public:
|
878
|
+
VALUE convert(const numo::SComplex& x) {
|
879
|
+
return x.value();
|
880
|
+
}
|
881
|
+
};
|
882
|
+
|
883
|
+
template<>
|
884
|
+
struct Type<numo::DComplex>
|
885
|
+
{
|
886
|
+
static bool verify() { return true; }
|
887
|
+
};
|
888
|
+
|
889
|
+
template<>
|
890
|
+
class From_Ruby<numo::DComplex>
|
891
|
+
{
|
892
|
+
public:
|
893
|
+
Convertible is_convertible(VALUE value) {
|
894
|
+
switch (rb_type(value))
|
704
895
|
{
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
896
|
+
case RUBY_T_DATA:
|
897
|
+
return Data_Type<numo::DComplex>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
898
|
+
case RUBY_T_ARRAY:
|
899
|
+
return Convertible::Cast;
|
900
|
+
default:
|
901
|
+
return Convertible::None;
|
902
|
+
}
|
903
|
+
}
|
904
|
+
|
905
|
+
numo::DComplex convert(VALUE x) {
|
906
|
+
return numo::DComplex(x);
|
907
|
+
}
|
908
|
+
};
|
909
|
+
|
910
|
+
template<>
|
911
|
+
class To_Ruby<numo::DComplex>
|
912
|
+
{
|
913
|
+
public:
|
914
|
+
VALUE convert(const numo::DComplex& x) {
|
915
|
+
return x.value();
|
916
|
+
}
|
917
|
+
};
|
918
|
+
|
919
|
+
template<>
|
920
|
+
struct Type<numo::Bit>
|
921
|
+
{
|
922
|
+
static bool verify() { return true; }
|
923
|
+
};
|
924
|
+
|
925
|
+
template<>
|
926
|
+
class From_Ruby<numo::Bit>
|
927
|
+
{
|
928
|
+
public:
|
929
|
+
Convertible is_convertible(VALUE value) {
|
930
|
+
switch (rb_type(value))
|
714
931
|
{
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
}
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
932
|
+
case RUBY_T_DATA:
|
933
|
+
return Data_Type<numo::Bit>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
934
|
+
case RUBY_T_ARRAY:
|
935
|
+
return Convertible::Cast;
|
936
|
+
default:
|
937
|
+
return Convertible::None;
|
938
|
+
}
|
939
|
+
}
|
940
|
+
|
941
|
+
numo::Bit convert(VALUE x) {
|
942
|
+
return numo::Bit(x);
|
943
|
+
}
|
944
|
+
};
|
945
|
+
|
946
|
+
template<>
|
947
|
+
class To_Ruby<numo::Bit>
|
948
|
+
{
|
949
|
+
public:
|
950
|
+
VALUE convert(const numo::Bit& x) {
|
951
|
+
return x.value();
|
952
|
+
}
|
953
|
+
};
|
954
|
+
|
955
|
+
template<>
|
956
|
+
struct Type<numo::RObject>
|
957
|
+
{
|
958
|
+
static bool verify() { return true; }
|
959
|
+
};
|
960
|
+
|
961
|
+
template<>
|
962
|
+
class From_Ruby<numo::RObject>
|
963
|
+
{
|
964
|
+
public:
|
965
|
+
Convertible is_convertible(VALUE value) {
|
966
|
+
switch (rb_type(value))
|
732
967
|
{
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
template<>
|
757
|
-
struct Type<numo::SComplex>
|
758
|
-
{
|
759
|
-
static bool verify()
|
760
|
-
{
|
761
|
-
return true;
|
762
|
-
}
|
763
|
-
};
|
968
|
+
case RUBY_T_DATA:
|
969
|
+
return Data_Type<numo::RObject>::is_descendant(value) ? Convertible::Exact : Convertible::None;
|
970
|
+
case RUBY_T_ARRAY:
|
971
|
+
return Convertible::Cast;
|
972
|
+
default:
|
973
|
+
return Convertible::None;
|
974
|
+
}
|
975
|
+
}
|
976
|
+
|
977
|
+
numo::RObject convert(VALUE x) {
|
978
|
+
return numo::RObject(x);
|
979
|
+
}
|
980
|
+
};
|
981
|
+
|
982
|
+
template<>
|
983
|
+
class To_Ruby<numo::RObject>
|
984
|
+
{
|
985
|
+
public:
|
986
|
+
VALUE convert(const numo::RObject& x) {
|
987
|
+
return x.value();
|
988
|
+
}
|
989
|
+
};
|
764
990
|
|
765
|
-
template<>
|
766
|
-
class From_Ruby<numo::SComplex>
|
767
|
-
{
|
768
|
-
public:
|
769
|
-
numo::SComplex convert(VALUE x)
|
770
|
-
{
|
771
|
-
return numo::SComplex(x);
|
772
|
-
}
|
773
|
-
};
|
774
|
-
|
775
|
-
template<>
|
776
|
-
class To_Ruby<numo::SComplex>
|
777
|
-
{
|
778
|
-
public:
|
779
|
-
VALUE convert(const numo::SComplex& x) {
|
780
|
-
return x.value();
|
781
|
-
}
|
782
|
-
};
|
783
|
-
|
784
|
-
template<>
|
785
|
-
struct Type<numo::DComplex>
|
786
|
-
{
|
787
|
-
static bool verify()
|
788
|
-
{
|
789
|
-
return true;
|
790
|
-
}
|
791
|
-
};
|
792
|
-
|
793
|
-
template<>
|
794
|
-
class From_Ruby<numo::DComplex>
|
795
|
-
{
|
796
|
-
public:
|
797
|
-
numo::DComplex convert(VALUE x)
|
798
|
-
{
|
799
|
-
return numo::DComplex(x);
|
800
|
-
}
|
801
|
-
};
|
802
|
-
|
803
|
-
template<>
|
804
|
-
class To_Ruby<numo::DComplex>
|
805
|
-
{
|
806
|
-
public:
|
807
|
-
VALUE convert(const numo::DComplex& x) {
|
808
|
-
return x.value();
|
809
|
-
}
|
810
|
-
};
|
811
|
-
|
812
|
-
template<>
|
813
|
-
struct Type<numo::Bit>
|
814
|
-
{
|
815
|
-
static bool verify()
|
816
|
-
{
|
817
|
-
return true;
|
818
|
-
}
|
819
|
-
};
|
820
|
-
|
821
|
-
template<>
|
822
|
-
class From_Ruby<numo::Bit>
|
823
|
-
{
|
824
|
-
public:
|
825
|
-
numo::Bit convert(VALUE x)
|
826
|
-
{
|
827
|
-
return numo::Bit(x);
|
828
|
-
}
|
829
|
-
};
|
830
|
-
|
831
|
-
template<>
|
832
|
-
class To_Ruby<numo::Bit>
|
833
|
-
{
|
834
|
-
public:
|
835
|
-
VALUE convert(const numo::Bit& x) {
|
836
|
-
return x.value();
|
837
|
-
}
|
838
|
-
};
|
839
|
-
|
840
|
-
template<>
|
841
|
-
struct Type<numo::RObject>
|
842
|
-
{
|
843
|
-
static bool verify()
|
844
|
-
{
|
845
|
-
return true;
|
846
|
-
}
|
847
|
-
};
|
848
|
-
|
849
|
-
template<>
|
850
|
-
class From_Ruby<numo::RObject>
|
851
|
-
{
|
852
|
-
public:
|
853
|
-
numo::RObject convert(VALUE x)
|
854
|
-
{
|
855
|
-
return numo::RObject(x);
|
856
|
-
}
|
857
|
-
};
|
858
|
-
|
859
|
-
template<>
|
860
|
-
class To_Ruby<numo::RObject>
|
861
|
-
{
|
862
|
-
public:
|
863
|
-
VALUE convert(const numo::RObject& x) {
|
864
|
-
return x.value();
|
865
|
-
}
|
866
|
-
};
|
867
991
|
}
|